[Pkg-javascript-commits] [node-evp-bytestokey] 24/29: rename keyLen to keyBits

Bastien Roucariès rouca at moszumanska.debian.org
Fri Sep 8 09:56:51 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 de52af54ce243d220a52e0a00a6c33b90e9847ba
Author: Daniel Cousens <github at dcousens.com>
Date:   Tue Sep 5 20:02:35 2017 +1000

    rename keyLen to keyBits
---
 README.md     |  2 +-
 index.js      | 16 +++++-----------
 test/index.js |  1 -
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index 748b341..36da238 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Use at least `scrypt` or `pbkdf2-hmac-sha256` instead.
 
 * `password` - `Buffer`, password used to derive the key data.
 * `salt` - 8 byte `Buffer` or `null`, salt is used as a salt in the derivation.
-* `keyLen` - `number`, key length in bytes.
+* `keyBits` - `number`, key length in **bits**.
 * `ivLen` - `number`, iv length in bytes.
 
 *Returns*: `{ key: Buffer, iv: Buffer }`
diff --git a/index.js b/index.js
index 9a91a86..f9d4757 100644
--- a/index.js
+++ b/index.js
@@ -2,20 +2,14 @@ var Buffer = require('safe-buffer').Buffer
 var MD5 = require('md5.js')
 
 /* eslint-disable camelcase */
-function EVP_BytesToKey (password, salt, keyLen, ivLen) {
-  if (!Buffer.isBuffer(password)) {
-    password = Buffer.from(password, 'binary')
-  }
+function EVP_BytesToKey (password, salt, keyBits, ivLen) {
+  if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary')
   if (salt) {
-    if (!Buffer.isBuffer(salt)) {
-      salt = Buffer.from(salt, 'binary')
-    }
-    if (salt.length !== 8) {
-      throw new RangeError('salt should be Buffer with 8 byte length')
-    }
+    if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary')
+    if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length')
   }
 
-  keyLen = keyLen / 8
+  var keyLen = keyBits / 8
   var key = Buffer.alloc(keyLen)
   var iv = Buffer.alloc(ivLen || 0)
   var tmp = Buffer.alloc(0)
diff --git a/test/index.js b/test/index.js
index def0583..f0b0273 100644
--- a/test/index.js
+++ b/test/index.js
@@ -38,7 +38,6 @@ for (var i = 0; i < 1000; ++i) {
     var result = EVP_BytesToKey(password, salt, keyLen, 0)
     var expected = OpenSSL_EVP_BytesToKey.md5_key32_iv0(salt, password, 1)
 
-    console.log(result, expected)
     t.same(result, expected)
     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