[Pkg-javascript-commits] [node-sha.js] 39/237: support multiple encodings
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:02:53 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 36506c6ded807f9a23014b4eb2385ec8ae5d681b
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Fri Dec 27 14:34:00 2013 +0700
support multiple encodings
---
hash.js | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/hash.js b/hash.js
index f3d3352..a14474b 100644
--- a/hash.js
+++ b/hash.js
@@ -1,6 +1,6 @@
var u = require('./util')
var hexpp = require('./hexpp').defaults({bigendian: false})
-
+var toBuffer = require('bops/typedarray/from')
module.exports = Hash
//prototype class for hash functions
@@ -26,9 +26,14 @@ Hash.prototype.update = function (data, enc) {
var bl = this._block.byteLength
//for now, assume ascii.
+ //I'd rather do this with a streaming encoder, like the opposite of
+ //http://nodejs.org/api/string_decoder.html
if('string' === typeof data && !enc)
- throw new Error('encoding is mandatory when data is string')
+ enc = 'utf8'
+ if(enc === 'base64' || enc === 'utf8')
+ data = toBuffer(data, enc), enc = null
+
var length = lengthOf(data, enc)
var l = this._len += length
var s = this._s = (this._s || 0)
@@ -75,8 +80,7 @@ Hash.prototype.digest = function (enc) {
X.setUint32(fl + 4, len, false) //big endian
var hash = this._update(this._block.buffer)
- if(!enc) return hash
- return u.toHex(hash)
+ return u.toString(hash, enc)
}
Hash.prototype._update = function () {
--
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