Add unit test to catch #156 and fix it
This commit is contained in:
parent
3b1955627b
commit
95db18eb4a
|
@ -9,10 +9,10 @@
|
|||
var desModule = require('./des.js');
|
||||
|
||||
module.exports = {
|
||||
/** @see module:crypto/cipher/des.des */
|
||||
des: desModule.des,
|
||||
/** @see module:crypto/cipher/des.originalDes */
|
||||
originalDes: desModule.originalDes,
|
||||
des: desModule.originalDes,
|
||||
/** @see module:crypto/cipher/des.des */
|
||||
tripledes: desModule.des,
|
||||
/** @see module:crypto/cipher/cast5 */
|
||||
cast5: require('./cast5.js'),
|
||||
/** @see module:crypto/cipher/twofish */
|
||||
|
|
|
@ -75,7 +75,7 @@ describe('TripleDES (EDE) cipher test with test vectors from http://csrc.nist.go
|
|||
|
||||
it('3DES EDE test vectors', function (done) {
|
||||
for (var i = 0; i < testvectors.length; i++) {
|
||||
var des = new openpgp.crypto.cipher.des(key);
|
||||
var des = new openpgp.crypto.cipher.tripledes(key);
|
||||
|
||||
var encr = util.bin2str(des.encrypt(testvectors[i][0], key));
|
||||
|
||||
|
@ -115,7 +115,7 @@ describe('TripleDES (EDE) cipher test with test vectors from http://csrc.nist.go
|
|||
[[0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D], [0xCA, 0x59, 0x61, 0x3A, 0x83, 0x23, 0x26, 0xDD]],
|
||||
[[0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F], [0x83, 0x25, 0x79, 0x06, 0x54, 0xA4, 0x44, 0xD9]]];
|
||||
|
||||
var des = new openpgp.crypto.cipher.originalDes(key);
|
||||
var des = new openpgp.crypto.cipher.des(key);
|
||||
|
||||
for (var padding = 0; padding < 3; padding++) {
|
||||
var thisVectorSet = testvectors[padding];
|
||||
|
|
|
@ -201,4 +201,70 @@ describe('Basic', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Message 3DES decryption", function() {
|
||||
var pgp_msg =
|
||||
['-----BEGIN PGP MESSAGE-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - http://gpgtools.org',
|
||||
'',
|
||||
'hIwDBU4Dycfvp2EBA/9tuhQgOrcATcm2PRmIOcs6q947YhlsBTZZdVJDfVjkKlyM',
|
||||
'M0yE+lnNplWb041Cpfkkl6IvorKQd2iPbAkOL0IXwmVN41l+PvVgMcuFvvzetehG',
|
||||
'Ca0/VEYOaTZRNqyr9FIzcnVy1I/PaWT3iqVAYa+G8TEA5Dh9RLfsx8ZA9UNIaNI+',
|
||||
'ASm9aZ3H6FerNhm8RezDY5vRn6xw3o/wH5YEBvV2BEmmFKZ2BlqFQxqChr8UNwd1',
|
||||
'Ieebnq0HtBPE8YU/L0U=',
|
||||
'=JyIa',
|
||||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
var priv_key =
|
||||
['-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
||||
'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)',
|
||||
'Comment: GPGTools - http://gpgtools.org',
|
||||
'',
|
||||
'lQH+BFLqLegBBAC/rN3g30Jrcpx5lTb7Kxe+ZfS7ppOIoBjjN+qcOh81cJJVS5dT',
|
||||
'UGcDsm2tCLVS3P2dGaYhfU9fsoSq/wK/tXsdoWXvXdjHbbueyi1kTZqlnyT190UE',
|
||||
'vmDxH0yqquvUaf7+CNXC0T6l9gGS9p0x7xNydWRb7zeK1wIsYI+dRGQmzQARAQAB',
|
||||
'/gMDArgQHMknurQXy0Pho3Nsdu6zCUNXuplvaSXruefKsQn6eexGPnecNTT2iy5N',
|
||||
'70EK371D7GcNhhLsn8roUcj1Hi3kR14wXW7lcQBy9RRbbglIJXIqKJ8ywBEO8BaQ',
|
||||
'b0plL+w5A9EvX0BQc4d53MTqySh6POsEDOxPzH4D/JWbaozfmc4LfGDqH1gl7ebY',
|
||||
'iu81vnBuuskjpz8rxRI81MldJEIObrTE2x46DF7AmS6L6u/Qz3AAmZd89p5INCdx',
|
||||
'DemxzuMKp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i',
|
||||
'Y61qtR0io52T7w69fBe9Q5/d5SwpwWKMpCTOqvvzdHX7JmeFtV+2vRVilIif7AfP',
|
||||
'AD+OjQ/OhMu3jYO+XNhm3raPT2tIBsBdl2UiHOnj4AUNuLuUJeVghtz4Qt6dvjyz',
|
||||
'PlBvSF+ESqALjM8IqnG15FX4LmEDFrFcfNCsnmeyZ2nr1h2mV5jOON0EmBtCyhCt',
|
||||
'D/Ivi4/SZk+tBVhsBI+7ZECZYDJzZQnyPDsUv31MU4OwdWi7FhzHvDj/0bhYY7+I',
|
||||
'nwQYAQIACQUCUuot6AIbDAAKCRCSTaGiPl24PwYAA/sGIHvCKWP5+4ZlBHuOdbP9',
|
||||
'9v3PXFCm61qFEL0DTSq7NgBcuf0ASRElRI3wIKlfkwaiSzVPfNLiMTexdc7XaiTz',
|
||||
'CHaOn1Xl2gmYTq2KiJkgtLuwptYU1iSj7vvSHKy0+nYIckOZB4pRCOjknT08O4ZJ',
|
||||
'22q10ausyQXoOxXfDWVwKA==',
|
||||
'=IkKW',
|
||||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
||||
|
||||
it('Decrypt message', function (done) {
|
||||
var privKey, message, decrypted;
|
||||
|
||||
privKey = openpgp.key.readArmored(priv_key).keys[0];
|
||||
privKey.decrypt('1234');
|
||||
message = openpgp.message.readArmored(pgp_msg);
|
||||
decrypted = openpgp.decryptMessage(privKey, message);
|
||||
|
||||
expect(decrypted).to.equal('hello 3des\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user