[Pkg-javascript-commits] [node-sha.js] 137/237: remove utils.js

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:03:47 UTC 2017


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

rouca pushed a commit to branch master
in repository node-sha.js.

commit 418d59d40315a50972244ab4103c6d2a59dd86a2
Author: Daniel Cousens <github at dcousens.com>
Date:   Thu Sep 4 16:02:59 2014 +1000

    remove utils.js
---
 hash.js | 51 ++++++++++++++++++---------------------------------
 util.js | 36 ------------------------------------
 2 files changed, 18 insertions(+), 69 deletions(-)

diff --git a/hash.js b/hash.js
index f50a03a..8a5e995 100644
--- a/hash.js
+++ b/hash.js
@@ -1,7 +1,3 @@
-var u = require('./util')
-var write = u.write
-var fill = u.zeroFill
-
 module.exports = function (Buffer) {
 
   //prototype class for hash functions
@@ -18,32 +14,15 @@ module.exports = function (Buffer) {
     this._len = 0
   }
 
-  function lengthOf(data, enc) {
-    if(enc == null)     return data.byteLength || data.length
-    if(enc == 'ascii' || enc == 'binary')  return data.length
-    if(enc == 'hex')    return data.length/2
-    if(enc == 'base64') return data.length/3
-  }
-
   Hash.prototype.update = function (data, enc) {
     var bl = this._blockSize
 
-    //I'd rather do this with a streaming encoder, like the opposite of
-    //http://nodejs.org/api/string_decoder.html
-    var length
-      if(!enc && 'string' === typeof data)
-        enc = 'utf8'
-
-    if(enc) {
-      if(enc === 'utf-8')
-        enc = 'utf8'
-
-      if(enc === 'base64' || enc === 'utf8')
-        data = new Buffer(data, enc), enc = null
+    if ("string" === typeof data) {
+      enc = enc || "utf8"
+      data = new Buffer(data, enc)
+    }
 
-      length = lengthOf(data, enc)
-    } else
-      length = data.byteLength || data.length
+    var length = data.length
 
     var l = this._len += length
     var s = this._s = (this._s || 0)
@@ -51,9 +30,15 @@ module.exports = function (Buffer) {
     var buffer = this._block
     while(s < l) {
       var t = Math.min(length, f + bl - s%bl)
-      write(buffer, data, enc, s%bl, f, t)
+
+      var l2 = (t - f)
+      for (var i = 0; i < l2; i++) {
+        buffer[s%bl + i] = data[i + f]
+      }
+
       var ch = (t - f);
-      s += ch; f += ch
+      s += ch;
+      f += ch
 
       if(!(s%bl))
         this._update(buffer)
@@ -61,9 +46,9 @@ module.exports = function (Buffer) {
     this._s = s
 
     return this
-
   }
 
+
   Hash.prototype.digest = function (enc) {
     var bl = this._blockSize
     var fl = this._finalSize
@@ -73,13 +58,13 @@ module.exports = function (Buffer) {
 
     var bits = len % (bl*8)
 
-    //add end marker, so that appending 0's creats a different hash.
+    // add end marker, so that appending 0's creates a different hash.
     x[this._len % bl] = 0x80
-    fill(this._block, this._len % bl + 1)
+    x.fill(0, this._len % this._blockSize + 1)
 
-    if(bits >= fl*8) {
+    if (bits >= fl*8) {
       this._update(this._block)
-      u.zeroFill(this._block, 0)
+      this._block.fill(0)
     }
 
     //TODO: handle case where the bit length is > Math.pow(2, 29)
diff --git a/util.js b/util.js
deleted file mode 100644
index 9944196..0000000
--- a/util.js
+++ /dev/null
@@ -1,36 +0,0 @@
-exports.write = write
-exports.zeroFill = zeroFill
-
-exports.toString = toString
-
-function write (buffer, string, enc, start, from, to, LE) {
-  var l = (to - from)
-  if(enc === 'ascii' || enc === 'binary') {
-    for( var i = 0; i < l; i++) {
-      buffer[start + i] = string.charCodeAt(i + from)
-    }
-  }
-  else if(enc == null) {
-    for( var i = 0; i < l; i++) {
-      buffer[start + i] = string[i + from]
-    }
-  }
-  else if(enc === 'hex') {
-    for(var i = 0; i < l; i++) {
-      var j = from + i
-      buffer[start + i] = parseInt(string[j*2] + string[(j*2)+1], 16)
-    }
-  }
-  else if(enc === 'base64') {
-    throw new Error('base64 encoding not yet supported')
-  }
-  else
-    throw new Error(enc +' encoding not yet supported')
-}
-
-//always fill to the end!
-function zeroFill(buf, from) {
-  for(var i = from; i < buf.length; i++)
-    buf[i] = 0
-}
-

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



More information about the Pkg-javascript-commits mailing list