Skip to content

Commit 4673ee7

Browse files
committed
Merge pull request #21 from eoger/master
Add backwards compatibility with Node 0.10
2 parents a894708 + d517ac2 commit 4673ee7

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

nodejs/ece.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var crypto = require('crypto');
44
var base64 = require('urlsafe-base64');
5+
require('./shim');
56

67
var savedKeys = {};
78
var keyLabels = {};
@@ -55,7 +56,8 @@ function HKDF(salt, ikm, info, len) {
5556

5657
function info(base, context) {
5758
var result = Buffer.concat([
58-
new Buffer('Content-Encoding: ' + base + '\0', 'ascii'),
59+
new Buffer('Content-Encoding: ' + base, 'ascii'),
60+
new Buffer('\0'),
5961
context
6062
]);
6163
keylog('info ' + base, result);
@@ -304,7 +306,8 @@ function encrypt(buffer, params) {
304306
function saveKey(id, key, dhLabel) {
305307
savedKeys[id] = key;
306308
if (dhLabel) {
307-
keyLabels[id] = new Buffer(dhLabel + '\0', 'ascii');
309+
keyLabels[id] = Buffer.concat([new Buffer(dhLabel, 'ascii'),
310+
new Buffer('\0')]);
308311
}
309312
}
310313

nodejs/package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@
55
"homepage": "https://github.com/martinthomson/encrypted-content-encoding",
66
"bugs": "https://github.com/martinthomson/encrypted-content-encoding/issues",
77
"author": {
8-
"name" : "Martin Thomson",
9-
"email" : "martin.thomson@gmail.com"
8+
"name": "Martin Thomson",
9+
"email": "martin.thomson@gmail.com"
1010
},
1111
"repository": {
1212
"type": "git",
1313
"url": "https://github.com/martinthomson/encrypted-content-encoding.git"
1414
},
1515
"license": "MIT",
1616
"main": "./ece.js",
17-
"scripts": { "test": "node ./test.js" },
18-
"engines" : { "node" : ">=4.0.0" },
17+
"scripts": {
18+
"test": "node ./test.js"
19+
},
20+
"engines": {
21+
"node": ">=0.10.0"
22+
},
1923
"dependencies": {
24+
"browserify-aes": "^1.0.6",
25+
"buffer-compare-shim": "^1.0.0",
26+
"buffer-io-shim": "^1.0.0",
27+
"create-ecdh": "~4.0.0",
28+
"semver": "~5.1.0",
2029
"urlsafe-base64": "~1.0.0"
2130
}
2231
}

nodejs/shim/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var semver = require('semver');
2+
if (semver.satisfies(process.version, '>= 0.12.0')) {
3+
return;
4+
}
5+
6+
require('buffer-compare-shim');
7+
require('buffer-io-shim');
8+
var crypto = require('crypto');
9+
crypto.createECDH = require('create-ecdh');
10+
crypto.createCipheriv = require('browserify-aes/encrypter').createCipheriv;
11+
crypto.createDecipheriv = require('browserify-aes/decrypter').createDecipheriv;

0 commit comments

Comments
 (0)