[Pkg-javascript-commits] [node-create-hash] 24/40: clean up/rename the md5 stuff

Bastien Roucariès rouca at moszumanska.debian.org
Sat May 27 14:10:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-create-hash.

commit 2befdb5f78c306d55589a9024c41b703d394bc5a
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Mon Oct 12 15:09:03 2015 -0400

    clean up/rename the md5 stuff
---
 helpers.js | 28 +++++++++-------------------
 md5.js     |  4 ++--
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/helpers.js b/helpers.js
index 429f68a..4b2c9f2 100644
--- a/helpers.js
+++ b/helpers.js
@@ -4,38 +4,28 @@ var zeroBuffer = new Buffer(intSize)
 zeroBuffer.fill(0)
 
 var charSize = 8
+var hashSize = 16
 
-function toArray (buf, bigEndian) {
+function toArray (buf) {
   if ((buf.length % intSize) !== 0) {
     var len = buf.length + (intSize - (buf.length % intSize))
     buf = Buffer.concat([buf, zeroBuffer], len)
   }
 
-  var arr = []
-  var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE
-  for (var i = 0; i < buf.length; i += intSize) {
-    arr.push(fn.call(buf, i))
+  var arr = new Array(buf.length >>> 2)
+  for (var i = 0, j = 0; i < buf.length; i += intSize, j++) {
+    arr[j] = buf.readInt32LE(i)
   }
 
   return arr
 }
 
-function toBuffer (arr, size, bigEndian) {
-  var buf = new Buffer(size)
-  var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE
 
+module.exports = function hash (buf, fn) {
+  var arr = fn(toArray(buf), buf.length * charSize)
+  var buf = new Buffer(hashSize)
   for (var i = 0; i < arr.length; i++) {
-    fn.call(buf, arr[i], i * 4, true)
+    buf.writeInt32LE(arr[i], i  << 2, true)
   }
-
   return buf
 }
-
-function hash (buf, fn, hashSize, bigEndian) {
-  if (!Buffer.isBuffer(buf)) buf = new Buffer(buf)
-
-  var arr = fn(toArray(buf, bigEndian), buf.length * charSize)
-  return toBuffer(arr, hashSize, bigEndian)
-}
-
-exports.hash = hash
diff --git a/md5.js b/md5.js
index 6ef16ea..55b5a94 100644
--- a/md5.js
+++ b/md5.js
@@ -8,7 +8,7 @@
  * See http://pajhome.org.uk/crypt/md5 for more info.
  */
 
-var helpers = require('./helpers')
+var makeHash = require('./make-hash')
 
 /*
  * Calculate the MD5 of an array of little-endian words, and a bit length
@@ -147,5 +147,5 @@ function bit_rol (num, cnt) {
 }
 
 module.exports = function md5 (buf) {
-  return helpers.hash(buf, core_md5, 16)
+  return makeHash(buf, core_md5)
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-create-hash.git



More information about the Pkg-javascript-commits mailing list