[Pkg-javascript-commits] [node-sha.js] 14/31: hash: increase readability of block-by-block hashing

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 30 11:23:26 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 e9ff865980615cb8ee2730c6868e7f6781af3c5b
Author: Daniel Cousens <github at dcousens.com>
Date:   Fri May 19 21:19:59 2017 +1000

    hash: increase readability of block-by-block hashing
---
 hash.js | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/hash.js b/hash.js
index eea15ac..ef9bf8c 100644
--- a/hash.js
+++ b/hash.js
@@ -14,27 +14,28 @@ Hash.prototype.update = function (data, enc) {
     data = new Buffer(data, enc)
   }
 
-  var s = this._len
-  var l = this._len += data.length
-  var f = 0
-  var buffer = this._block
+  var block = this._block
+  var blockSize = this._blockSize
+  var length = data.length
+  var accum = this._len
 
-  while (s < l) {
-    var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
-    var ch = (t - f)
+  for (var offset = 0; offset < length;) {
+    var assigned = accum % blockSize
+    var remainder = Math.min(length - offset, blockSize - assigned)
 
-    for (var i = 0; i < ch; i++) {
-      buffer[(s % this._blockSize) + i] = data[i + f]
+    for (var i = 0; i < remainder; i++) {
+      block[assigned + i] = data[offset + i]
     }
 
-    s += ch
-    f += ch
+    accum += remainder
+    offset += remainder
 
-    if ((s % this._blockSize) === 0) {
-      this._update(buffer)
+    if ((accum % blockSize) === 0) {
+      this._update(block)
     }
   }
 
+  this._len += length
   return this
 }
 

-- 
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