Skip to content

Commit 3571b58

Browse files
authored
Merge pull request #56 from joseluisdiaz/fix-async-dep
Remove async as a dep.
2 parents 887c7a3 + 9a879ae commit 3571b58

File tree

3 files changed

+77
-55
lines changed

3 files changed

+77
-55
lines changed

Diff for: .travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
3-
- 0.10
43
- 4
54
- 6
65
- 8
6+
- 10
7+
- 12

Diff for: lib/xmlenc.js

+73-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var crypto = require('crypto');
2-
var async = require('async');
32
var xmldom = require('xmldom');
43
var xpath = require('xpath');
54
var utils = require('./utils');
@@ -59,60 +58,83 @@ function encrypt(content, options, callback) {
5958

6059
options.input_encoding = options.input_encoding || 'utf8';
6160

62-
async.waterfall([
63-
function generate_symmetric_key(cb) {
64-
switch (options.encryptionAlgorithm) {
65-
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
66-
crypto.randomBytes(16, cb); // generate a symmetric random key 16 bytes length
67-
break;
68-
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
69-
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
70-
break;
71-
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
72-
crypto.randomBytes(24, cb); // generate a symmetric random key 24 bytes (192 bits) length
73-
break;
74-
default:
75-
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
76-
}
77-
},
78-
function encrypt_content(symmetricKey, cb) {
79-
switch (options.encryptionAlgorithm) {
80-
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
81-
encryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
82-
if (err) return cb(err);
83-
cb(null, symmetricKey, encryptedContent);
84-
});
85-
break;
86-
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
87-
encryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
88-
if (err) return cb(err);
89-
cb(null, symmetricKey, encryptedContent);
90-
});
91-
break;
92-
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
93-
encryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, content, options.input_encoding, function (err, encryptedContent) {
94-
if (err) return cb(err);
95-
cb(null, symmetricKey, encryptedContent);
96-
});
97-
break;
98-
default:
99-
cb(new Error('encryption algorithm not supported'));
100-
}
101-
},
102-
function encrypt_key(symmetricKey, encryptedContent, cb) {
103-
encryptKeyInfo(symmetricKey, options, function(err, keyInfo) {
104-
if (err) return cb(err);
105-
106-
var result = utils.renderTemplate('encrypted-key', {
107-
encryptedContent: encryptedContent.toString('base64'),
108-
keyInfo: keyInfo,
109-
contentEncryptionMethod: options.encryptionAlgorithm
61+
function generate_symmetric_key(cb) {
62+
switch (options.encryptionAlgorithm) {
63+
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
64+
crypto.randomBytes(16, cb); // generate a symmetric random key 16 bytes length
65+
break;
66+
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
67+
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
68+
break;
69+
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
70+
crypto.randomBytes(24, cb); // generate a symmetric random key 24 bytes (192 bits) length
71+
break;
72+
default:
73+
crypto.randomBytes(32, cb); // generate a symmetric random key 32 bytes length
74+
}
75+
}
76+
77+
function encrypt_content(symmetricKey, cb) {
78+
switch (options.encryptionAlgorithm) {
79+
case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc':
80+
encryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
81+
if (err) return cb(err);
82+
cb(null, encryptedContent);
83+
});
84+
break;
85+
case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc':
86+
encryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, content, options.input_encoding, function (err, encryptedContent) {
87+
if (err) return cb(err);
88+
cb(null, encryptedContent);
11089
});
90+
break;
91+
case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc':
92+
encryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, content, options.input_encoding, function (err, encryptedContent) {
93+
if (err) return cb(err);
94+
cb(null, encryptedContent);
95+
});
96+
break;
97+
default:
98+
cb(new Error('encryption algorithm not supported'));
99+
}
100+
}
111101

112-
cb(null, result);
102+
function encrypt_key(symmetricKey, encryptedContent, cb) {
103+
encryptKeyInfo(symmetricKey, options, function(err, keyInfo) {
104+
if (err) return cb(err);
105+
106+
var result = utils.renderTemplate('encrypted-key', {
107+
encryptedContent: encryptedContent.toString('base64'),
108+
keyInfo: keyInfo,
109+
contentEncryptionMethod: options.encryptionAlgorithm
113110
});
111+
112+
cb(null, result);
113+
});
114+
}
115+
116+
117+
generate_symmetric_key(function (genKeyError, symmetricKey) {
118+
if (genKeyError) {
119+
return callback(genKeyError);
114120
}
115-
], callback);
121+
122+
encrypt_content(symmetricKey, function(encryptContentError, encryptedContent) {
123+
if (encryptContentError) {
124+
return callback(encryptContentError);
125+
}
126+
127+
encrypt_key(symmetricKey, encryptedContent, function (encryptKeyError, result) {
128+
if (encryptKeyError) {
129+
return callback(encryptKeyError);
130+
}
131+
132+
callback(null, result);
133+
});
134+
135+
});
136+
137+
});
116138
}
117139

118140
function decrypt(xml, options, callback) {

Diff for: package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xml-encryption",
3-
"version": "0.11.2",
3+
"version": "0.12.0",
44
"devDependencies": {
55
"mocha": "3.3.0",
66
"should": "^11.2.1"
@@ -19,7 +19,6 @@
1919
],
2020
"license": "MIT",
2121
"dependencies": {
22-
"async": "^2.1.5",
2322
"ejs": "^2.5.6",
2423
"node-forge": "^0.7.0",
2524
"xmldom": "~0.1.15",
@@ -29,6 +28,6 @@
2928
"test": "mocha"
3029
},
3130
"engines": {
32-
"node": ">=0.10"
31+
"node": ">=4"
3332
}
3433
}

0 commit comments

Comments
 (0)