Comparing version 1.2.2 to 1.3.0
@@ -20,3 +20,3 @@ var u = require('./util') | ||
if(enc == null) return data.byteLength || data.length | ||
if(enc == 'ascii') return data.length | ||
if(enc == 'ascii' || enc == 'binary') return data.length | ||
if(enc == 'hex') return data.length/2 | ||
@@ -23,0 +23,0 @@ if(enc == 'base64') return data.length/3 |
{ | ||
"name": "sha.js", | ||
"description": "streaming sha1 hash in pure javascript", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/dominictarr/sha.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -30,2 +30,4 @@ var Sha1 = require('../sha1') | ||
var base64 = new Sha1().update(toString(EMPTY, 'base64'), 'base64').digest('hex') | ||
console.log('Binary:', JSON.stringify(toString(EMPTY, 'binary'))) | ||
var binary = new Sha1().update(toString(EMPTY, 'binary'), 'binary').digest('hex') | ||
var buffer = new Sha1().update(EMPTY).digest('hex') | ||
@@ -35,4 +37,5 @@ console.log(hex, base64, buffer) | ||
t.equal(hex, buffer) | ||
t.equal(hex, binary) | ||
t.end() | ||
}) | ||
15
util.js
@@ -23,3 +23,3 @@ exports.write = write | ||
var l = (to - from) | ||
if(enc === 'ascii') { | ||
if(enc === 'ascii' || enc === 'binary') { | ||
for( var i = 0; i < l; i++) { | ||
@@ -58,2 +58,13 @@ buffer[start + i] = string.charCodeAt(i + from) | ||
function toBinary (buf) { | ||
var s = '' | ||
var l = 'string' === typeof buf ? buf.length : buf.byteLength | ||
var s = '' | ||
for(var i = 0; i < l; i++) { | ||
var char = buf.charCodeAt ? buf.charCodeAt(i) : buf[i] | ||
s += String.fromCharCode(char) | ||
} | ||
return s | ||
} | ||
//always fill to the end! | ||
@@ -69,3 +80,5 @@ function zeroFill(buf, from) { | ||
return toHex(buf) | ||
if('binary' == enc) | ||
return toBinary(buf) | ||
return bopsToString(buf, enc) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
796922
3491