Make ECC tests less idiosyncratic

This commit is contained in:
Daniel Huigens 2018-07-27 14:57:42 +02:00
parent aa3ede94ec
commit 225f586970
5 changed files with 11 additions and 6 deletions

View File

@ -118,6 +118,8 @@ describe('Brainpool Cryptography', function () {
'second test message', 'second test message',
'', '',
'-----BEGIN PGP SIGNATURE-----', '-----BEGIN PGP SIGNATURE-----',
'Version: OpenPGP.js v3.1.0',
'Comment: https://openpgpjs.org',
'', '',
'wl4EARMKABAFAltbE34JEDfhaphrivmeAABaXQD+LzOhFxTqz8+IcaD3xzww', 'wl4EARMKABAFAltbE34JEDfhaphrivmeAABaXQD+LzOhFxTqz8+IcaD3xzww',
'EjEn0u7qgCFem9PHPD4wqAcA/1WQE3N7DIwRG45HFd+ZBo4vcuRkWK+Q6CHl', 'EjEn0u7qgCFem9PHPD4wqAcA/1WQE3N7DIwRG45HFd+ZBo4vcuRkWK+Q6CHl',
@ -125,6 +127,7 @@ describe('Brainpool Cryptography', function () {
'=obwy', '=obwy',
'-----END PGP SIGNATURE-----' '-----END PGP SIGNATURE-----'
].join('\n') ].join('\n')
} }
}; };
async function load_pub_key(name) { async function load_pub_key(name) {

View File

@ -106,8 +106,8 @@ describe('Elliptic Curve Cryptography', function () {
'O Romeo, Romeo! Wherefore art thou Romeo?', 'O Romeo, Romeo! Wherefore art thou Romeo?',
'', '',
'-----BEGIN PGP SIGNATURE-----', '-----BEGIN PGP SIGNATURE-----',
'Version: GnuPG v2', 'Version: OpenPGP.js v3.1.0',
'Comment: GnuPG v2.1+libgcrypt-1.7', 'Comment: https://openpgpjs.org',
'', '',
'wl4EARMIABAFAltbFFMJEGQRYCGVm9/gAAAjugD/W/OZ++qiNlhy08OOflAN', 'wl4EARMIABAFAltbFFMJEGQRYCGVm9/gAAAjugD/W/OZ++qiNlhy08OOflAN',
'rjjX3rknSZyUkr96HD4VWVsBAPL9QjyHI3714cdkQmwYGiG8TVrtPetnqHho', 'rjjX3rknSZyUkr96HD4VWVsBAPL9QjyHI3714cdkQmwYGiG8TVrtPetnqHho',

View File

@ -431,7 +431,7 @@ function tests() {
}); });
expect(util.isStream(decrypted.data)).to.equal(expectedType); expect(util.isStream(decrypted.data)).to.equal(expectedType);
const reader = openpgp.stream.getReader(decrypted.data); const reader = openpgp.stream.getReader(decrypted.data);
expect((await reader.peekBytes(200)).toString('utf8').substr(0, 50)).to.equal(plaintext[0]); expect((await reader.peekBytes(256)).toString('utf8').substr(0, 64)).to.equal(plaintext[0]);
if (i > 10) throw new Error('Data did not arrive early.'); if (i > 10) throw new Error('Data did not arrive early.');
expect((await reader.readToEnd()).toString('utf8')).to.equal(util.concat(plaintext)); expect((await reader.readToEnd()).toString('utf8')).to.equal(util.concat(plaintext));
} finally { } finally {

View File

@ -1,6 +1,6 @@
/** /**
* Generates a 50 character long javascript string out of the whole utf-8 range. * Generates a 64 character long javascript string out of the whole utf-8 range.
*/ */
function createSomeMessage(){ function createSomeMessage(){
const length = 50; const length = 50;
@ -9,7 +9,7 @@ function createSomeMessage(){
arr.push(String.fromCharCode( arr.push(String.fromCharCode(
Math.floor(Math.random() * 10174) + 1)); Math.floor(Math.random() * 10174) + 1));
} }
return arr.join('').replace(/\r/g, '\n'); return ' \t' + arr.join('').replace(/\r/g, '\n') + ' \t\n한국어/조선말';
} }
module.exports = { module.exports = {

View File

@ -54,6 +54,8 @@ describe('X25519 Cryptography', function () {
'Hi, Light wrote this!', 'Hi, Light wrote this!',
'', '',
'-----BEGIN PGP SIGNATURE-----', '-----BEGIN PGP SIGNATURE-----',
'Version: OpenPGP.js v3.1.0',
'Comment: https://openpgpjs.org',
'', '',
'wl4EARYKABAFAltbFNAJEB7N8CbAJFgwAAAhcAEA5b2MIQNxQYj8TAMyuhZJ', 'wl4EARYKABAFAltbFNAJEB7N8CbAJFgwAAAhcAEA5b2MIQNxQYj8TAMyuhZJ',
'UvxEgPS8DU59Kxw5F9+oldQBAN4mA+SOJyTxEx4oyyLh+8RD27dqyeDpmXju', 'UvxEgPS8DU59Kxw5F9+oldQBAN4mA+SOJyTxEx4oyyLh+8RD27dqyeDpmXju',
@ -178,7 +180,7 @@ describe('X25519 Cryptography', function () {
const result = await openpgp.verify({ publicKeys: [pub], message: msg}); const result = await openpgp.verify({ publicKeys: [pub], message: msg});
expect(result).to.exist; expect(result).to.exist;
expect(result.data).to.equal(randomData); expect(result.data).to.equal(openpgp.util.removeTrailingSpaces(randomData));
expect(result.signatures).to.have.length(1); expect(result.signatures).to.have.length(1);
expect(result.signatures[0].valid).to.be.true; expect(result.signatures[0].valid).to.be.true;
}); });