[Pkg-javascript-commits] [node-evp-bytestokey] 11/29: use safe-buffer
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Sep 8 09:56:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-evp-bytestokey.
commit 28e47c2e0036af7535f7a9092a6f8ca5ff9fa0fc
Author: Daniel Cousens <github at dcousens.com>
Date: Wed May 24 17:31:49 2017 +1000
use safe-buffer
---
index.js | 11 ++++++-----
package.json | 5 ++++-
test/index.js | 3 ++-
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/index.js b/index.js
index a3f510e..3137a65 100644
--- a/index.js
+++ b/index.js
@@ -1,13 +1,15 @@
+var Buffer = require('safe-buffer').Buffer
+
/* eslint-disable camelcase */
function EVP_BytesToKey (createHash, salt, data, count, keyLen, ivLen) {
if (Buffer.isBuffer(salt) && salt.length !== 8) {
throw new RangeError('salt should be Buffer with 8 byte length')
}
- var key = new Buffer(keyLen)
- var iv = new Buffer(ivLen)
+ var key = Buffer.alloc(keyLen)
+ var iv = Buffer.alloc(ivLen)
+ var mdBuf = Buffer.alloc(0)
- var mdBuf = new Buffer(0)
while (keyLen > 0 || ivLen > 0) {
var hash = createHash()
hash.update(mdBuf)
@@ -36,8 +38,7 @@ function EVP_BytesToKey (createHash, salt, data, count, keyLen, ivLen) {
}
}
- for (var j = 0; j < mdBuf.length; ++j) mdBuf[j] = 0
-
+ mdBuf.fill(0)
return { key: key, iv: iv }
}
diff --git a/package.json b/package.json
index fd8ffba..62eb8bf 100644
--- a/package.json
+++ b/package.json
@@ -37,5 +37,8 @@
"standard": "^8.0.0",
"tape": "^4.6.0"
},
- "gypfile": true
+ "gypfile": true,
+ "dependencies": {
+ "safe-buffer": "^5.1.1"
+ }
}
diff --git a/test/index.js b/test/index.js
index 138c74f..31e8cdd 100644
--- a/test/index.js
+++ b/test/index.js
@@ -6,6 +6,7 @@ try {
process.exit(1)
}
+var Buffer = require('safe-buffer').Buffer
var OpenSSL_EVP_BytesToKey = require('bindings')('OpenSSL_EVP_BytesToKey')
var crypto = require('crypto')
var test = require('tape')
@@ -43,7 +44,7 @@ for (var i = 0; i < counts.length; ++i) {
test('salt buffer length is 7', function (t) {
t.throws(function () {
- EVP_BytesToKey(createHashMD5, new Buffer(7))
+ EVP_BytesToKey(createHashMD5, Buffer.alloc(7))
}, /^RangeError: salt should be Buffer with 8 byte length$/)
t.end()
})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-evp-bytestokey.git
More information about the Pkg-javascript-commits
mailing list