From c486c962dc88dc3add5081137f085f3ba3fcb005 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sun, 24 Jan 2021 15:31:13 -0400 Subject: [PATCH 1/2] Fix deprecation warnings and update deps --- example/bundle.js | 13 ++----------- example/test.js | 1 - index.js | 13 ------------- package.json | 34 +++++++++++++++++----------------- test/create-hash.js | 6 +++--- test/create-hmac.js | 4 ++-- test/public-encrypt.js | 22 +++++++++++----------- test/sign.js | 12 ++++++------ 8 files changed, 41 insertions(+), 64 deletions(-) diff --git a/example/bundle.js b/example/bundle.js index 02698cc..bf7a182 100644 --- a/example/bundle.js +++ b/example/bundle.js @@ -395,17 +395,7 @@ exports.createHash = function (alg) { } } // the least I can do is make error messages for the rest of the node.js/crypto api. -;['createCredentials' -, 'createHmac' -, 'createCypher' -, 'createCypheriv' -, 'createDecipher' -, 'createDecipheriv' -, 'createSign' -, 'createVerify' -, 'createDeffieHellman', -, 'pbkdf2', -, 'randomBytes' ].forEach(function (name) { +;['createCredentials'].forEach(function (name) { exports[name] = function () { error('sorry,', name, 'is not implemented yet') } @@ -429,6 +419,7 @@ exports.str_sha1 = str_sha1; exports.hex_hmac_sha1 = hex_hmac_sha1; exports.b64_hmac_sha1 = b64_hmac_sha1; exports.str_hmac_sha1 = str_hmac_sha1; +exports.sha1_vm_test = sha1_vm_test; /* * Configurable variables. You may need to tweak these to be compatible with diff --git a/example/test.js b/example/test.js index 0b76c01..95cb0a3 100644 --- a/example/test.js +++ b/example/test.js @@ -1,4 +1,3 @@ var crypto = require('crypto') var abc = crypto.createHash('sha1').update('abc').digest('hex') console.log(abc) -// require('hello').inlineCall().call2() diff --git a/index.js b/index.js index b6d4d24..8b33eca 100644 --- a/index.js +++ b/index.js @@ -52,19 +52,6 @@ exports.privateEncrypt = publicEncrypt.privateEncrypt exports.publicDecrypt = publicEncrypt.publicDecrypt exports.privateDecrypt = publicEncrypt.privateDecrypt -// the least I can do is make error messages for the rest of the node.js/crypto api. -// ;[ -// 'createCredentials' -// ].forEach(function (name) { -// exports[name] = function () { -// throw new Error([ -// 'sorry, ' + name + ' is not implemented yet', -// 'we accept pull requests', -// 'https://github.com/crypto-browserify/crypto-browserify' -// ].join('\n')) -// } -// }) - var rf = require('randomfill') exports.randomFill = rf.randomFill diff --git a/package.json b/package.json index 7de383b..038bc93 100644 --- a/package.json +++ b/package.json @@ -11,32 +11,32 @@ "scripts": { "standard": "standard", "test": "npm run standard && npm run unit", - "unit": "node test/", + "unit": "node test", "browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js" }, "engines": { "node": "*" }, "dependencies": { - "browserify-cipher": "^1.0.0", - "browserify-sign": "^4.0.0", - "create-ecdh": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.0", - "diffie-hellman": "^5.0.0", - "inherits": "^2.0.1", - "pbkdf2": "^3.0.3", - "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" + "browserify-cipher": "^1.0.1", + "browserify-sign": "^4.2.1", + "create-ecdh": "^4.0.4", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "diffie-hellman": "^5.0.3", + "inherits": "^2.0.4", + "pbkdf2": "^3.1.1", + "public-encrypt": "^4.0.3", + "randombytes": "^2.1.0", + "randomfill": "^1.0.4" }, "devDependencies": { - "hash-test-vectors": "~1.3.2", + "hash-test-vectors": "^1.3.2", "pseudorandombytes": "^2.0.0", - "safe-buffer": "^5.1.1", - "standard": "^5.0.2", - "tape": "~2.3.2", - "zuul": "^3.6.0" + "safe-buffer": "^5.2.1", + "standard": "^5.4.1", + "tape": "^5.1.1", + "zuul": "^3.12.0" }, "optionalDependencies": {}, "browser": { diff --git a/test/create-hash.js b/test/create-hash.js index 33532fd..9689b1d 100644 --- a/test/create-hash.js +++ b/test/create-hash.js @@ -21,7 +21,7 @@ function runTest (name, createHash, algorithm) { } var obj = vectors[i] - var input = new Buffer(obj.input, 'base64') + var input = Buffer.from(obj.input, 'base64') var node = obj[algorithm] var js = createHash(algorithm).update(input).digest('hex') if (js !== node) { @@ -29,14 +29,14 @@ function runTest (name, createHash, algorithm) { } encodings.forEach(function (encoding) { - var input = new Buffer(obj.input, 'base64').toString(encoding) + var input = Buffer.from(obj.input, 'base64').toString(encoding) var node = obj[algorithm] var js = createHash(algorithm).update(input, encoding).digest('hex') if (js !== node) { t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node) } }) - input = new Buffer(obj.input, 'base64') + input = Buffer.from(obj.input, 'base64') node = obj[algorithm] var hash = createHash(algorithm) hash.end(input) diff --git a/test/create-hmac.js b/test/create-hmac.js index 08488ab..b77bf05 100644 --- a/test/create-hmac.js +++ b/test/create-hmac.js @@ -14,7 +14,7 @@ function testLib (name, createHmac) { return t.end() } var input = vectors[i] - var output = createHmac(alg, new Buffer(input.key, 'hex')) + var output = createHmac(alg, Buffer.from(input.key, 'hex')) .update(input.data, 'hex').digest() output = input.truncate ? output.slice(0, input.truncate) : output @@ -33,7 +33,7 @@ function testLib (name, createHmac) { return t.end() } var input = vectors[i] - var hmac = createHmac(alg, new Buffer(input.key, 'hex')) + var hmac = createHmac(alg, Buffer.from(input.key, 'hex')) hmac.end(input.data, 'hex') var output = hmac.read() diff --git a/test/public-encrypt.js b/test/public-encrypt.js index edb435c..2f64745 100644 --- a/test/public-encrypt.js +++ b/test/public-encrypt.js @@ -5,23 +5,23 @@ var rsa = { 'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a' } var crypto2 = require('public-encrypt/browser') -rsa.private = new Buffer(rsa.private, 'hex') -rsa.public = new Buffer(rsa.public, 'hex') +rsa.private = Buffer.from(rsa.private, 'hex') +rsa.public = Buffer.from(rsa.public, 'hex') var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280' test('publicEncrypt/privateDecrypt', function (t) { t.test('can decrypt', function (t) { t.plan(2) - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') - t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') + // note encryption is randomized so can't test to see if they encrypt the same + t.equals(crypto1.privateDecrypt(rsa.private, Buffer.from(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') + t.equals(crypto2.privateDecrypt(rsa.private, Buffer.from(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly') }) t.test('can round trip', function (t) { t.plan(2) var msg = 'this is a message' - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') - t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it') + // note encryption is randomized so can't test to see if they encrypt the same + t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, Buffer.from(msg))).toString(), msg, 'round trip it') + t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, Buffer.from(msg))).toString(), msg, 'round trip it') }) }) @@ -29,8 +29,8 @@ test('privateEncrypt/publicDecrypt', function (t) { t.test('can round trip', function (t) { t.plan(2) var msg = 'this is a message' - // note encryption is ranomized so can't test to see if they encrypt the same - t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') - t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it') + // note encryption is randomized so can't test to see if they encrypt the same + t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, Buffer.from(msg))).toString(), msg, 'round trip it') + t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, Buffer.from(msg))).toString(), msg, 'round trip it') }) }) diff --git a/test/sign.js b/test/sign.js index c91b666..5812b0d 100644 --- a/test/sign.js +++ b/test/sign.js @@ -12,10 +12,10 @@ var ec = { 'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a' } -rsa.private = new Buffer(rsa.private, 'hex') -rsa.public = new Buffer(rsa.public, 'hex') -ec.private = new Buffer(ec.private, 'hex') -ec.public = new Buffer(ec.public, 'hex') +rsa.private = Buffer.from(rsa.private, 'hex') +rsa.public = Buffer.from(rsa.public, 'hex') +ec.private = Buffer.from(ec.private, 'hex') +ec.public = Buffer.from(ec.public, 'hex') function testit (keys, message, scheme) { var pub = keys.public @@ -55,5 +55,5 @@ function testit (keys, message, scheme) { }) } -testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256') -testit(ec, new Buffer('ec with sha1'), 'sha256') +testit(rsa, Buffer.from('rsa with sha256'), 'RSA-SHA256') +testit(ec, Buffer.from('ec with sha1'), 'sha256') From f456ded1c1c77290ee664ae8ea6a0d2d27813ef3 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Tue, 2 Feb 2021 11:08:11 -0400 Subject: [PATCH 2/2] Add sideEffects: false to package.json Fixes https://github.com/crypto-browserify/crypto-browserify/issues/197 --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 038bc93..34c97a9 100644 --- a/package.json +++ b/package.json @@ -42,5 +42,6 @@ "browser": { "crypto": false }, - "license": "MIT" + "license": "MIT", + "sideEffects": "false" }