Skip to content

Commit a7b15fc

Browse files
gnareaziluvatar
authored andcommitted
Make sure that Node 6-8 is supported (#41)
* Make sure that Node 6+ is supported * Set last version of Mocha known to have worked
1 parent 4dfd555 commit a7b15fc

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
language: node_js
22
node_js:
3-
- 0.10
3+
- 0.10
4+
- 4
5+
- 6
6+
- 8

lib/xmlenc.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,10 @@ function decryptKeyInfo(doc, options) {
182182
}
183183

184184
function decryptKeyInfoWithScheme(encryptedKey, options, scheme) {
185-
try {
186-
var key = new Buffer(encryptedKey.textContent, 'base64').toString('binary');
187-
var private_key = pki.privateKeyFromPem(options.key);
188-
var decrypted = private_key.decrypt(key, scheme);
189-
return new Buffer(decrypted, 'binary');
190-
}
191-
catch (e) {
192-
throw e;
193-
}
185+
var key = new Buffer(encryptedKey.textContent, 'base64').toString('binary');
186+
var private_key = pki.privateKeyFromPem(options.key);
187+
var decrypted = private_key.decrypt(key, scheme);
188+
return new Buffer(decrypted, 'binary');
194189
}
195190

196191
function encryptWithAlgorithm(algorithm, symmetricKey, ivLength, content, encoding, callback) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "xml-encryption",
33
"version": "0.11.0",
44
"devDependencies": {
5-
"mocha": "*",
5+
"mocha": "3.3.0",
66
"should": "^11.2.1"
77
},
88
"main": "./lib",

test/xmlenc.encryptedkey.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
var assert = require('assert'),
2-
fs = require('fs'),
3-
xmlenc = require('../lib');
4-
5-
var crypto = require('crypto');
6-
var xmldom = require('xmldom');
1+
var assert = require('assert');
2+
var fs = require('fs');
3+
var xmlenc = require('../lib');
74
var xpath = require('xpath');
85

96
describe('encrypt', function() {
@@ -65,15 +62,18 @@ describe('encrypt', function() {
6562
keyEncryptionAlgorighm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'
6663
};
6764

68-
crypto.randomBytes(32, function(err, randomBytes) {
65+
var plaintext = 'The quick brown fox jumps over the lazy dog';
66+
67+
xmlenc.encryptKeyInfo(plaintext, options, function(err, encryptedKeyInfo) {
6968
if (err) return done(err);
70-
xmlenc.encryptKeyInfo(randomBytes, options, function(err, result) {
71-
if (err) return done(err);
72-
var decryptedRandomBytes = xmlenc.decryptKeyInfo(result, { key: fs.readFileSync(__dirname + '/test-auth0.key')});
7369

74-
assert.equal(new Buffer(randomBytes).toString('base64'), new Buffer(decryptedRandomBytes).toString('base64'));
75-
done();
76-
});
70+
var decryptedKeyInfo = xmlenc.decryptKeyInfo(
71+
encryptedKeyInfo,
72+
{key: fs.readFileSync(__dirname + '/test-auth0.key')}
73+
);
74+
assert.equal(decryptedKeyInfo.toString(), plaintext);
75+
76+
done();
7777
});
7878
});
7979

0 commit comments

Comments
 (0)