Comparing version 0.0.0 to 1.0.0
12
hash.js
var u = require('./util') | ||
var hexpp = require('./hexpp').defaults({bigendian: false}) | ||
var toBuffer = require('bops/typedarray/from') | ||
module.exports = Hash | ||
@@ -29,5 +29,10 @@ | ||
//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) | ||
@@ -79,4 +84,3 @@ var l = this._len += length | ||
var hash = this._update(this._block.buffer) | ||
if(!enc) return hash | ||
return u.toHex(hash) | ||
return u.toString(hash, enc) | ||
} | ||
@@ -83,0 +87,0 @@ |
11
index.js
@@ -14,3 +14,3 @@ /* | ||
var zeroFill = u.zeroFill | ||
module.exports = Sha | ||
module.exports = Sha1 | ||
@@ -20,3 +20,3 @@ var inherits = require('util').inherits | ||
inherits(Sha, Hash) | ||
inherits(Sha1, Hash) | ||
@@ -33,3 +33,4 @@ var q = false | ||
function Sha () { | ||
function Sha1 () { | ||
if(!(this instanceof Sha1)) return new Sha1() | ||
@@ -55,3 +56,3 @@ this._w = new Uint32Array(80) | ||
Sha.prototype._update = function (array) { | ||
Sha1.prototype._update = function (array) { | ||
@@ -106,3 +107,3 @@ var X = this._dv | ||
return H.buffer | ||
return h | ||
} | ||
@@ -109,0 +110,0 @@ |
{ | ||
"name": "sha.js", | ||
"description": "streaming sha1 hash in pure javascript", | ||
"version": "0.0.0", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/dominictarr/sha.js", | ||
@@ -10,3 +10,5 @@ "repository": { | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"bops": "~0.1.1" | ||
}, | ||
"devDependencies": { | ||
@@ -13,0 +15,0 @@ "tape": "~2.3.2" |
# sha.js | ||
Streamable SHA1 hash in pure javascript. | ||
[![build status](https://secure.travis-ci.org/dominictarr/sha.js.png)](http://travis-ci.org/dominictarr/sha.js) | ||
[![testling badge](https://ci.testling.com/dominictarr/sha.js.png)](https://ci.testling.com/dominictarr/sha.js) | ||
## Example | ||
``` js | ||
var Sha1 = require('sha.js') | ||
var h = new Sha1().update('abc', 'utf8').digest('hex') | ||
console.log(h) //a9993e364706816aba3e25717850c26c9cd0d89d | ||
``` | ||
## Note | ||
Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial. | ||
but is does update incrementally, so you can hash things larger than ram, and also, since it reuses | ||
the typedarrays, it uses a constant amount of memory (except when using base64 or utf8 encoding, | ||
see code comments) | ||
## Acknowledgements | ||
This work is derived from Paul Johnston's ["A JavaScript implementation of the Secure Hash Algorithm"] | ||
(http://pajhome.org.uk/crypt/md5/sha1.html) | ||
## License | ||
MIT |
var tape = require('tape') | ||
var write = require('../util').write | ||
var hexpp = require('../hexpp') | ||
var b64 = require('base64-js') | ||
var u = require('../util') | ||
var to = require('bops/typedarray/to') | ||
@@ -33,5 +33,5 @@ function toBuffer (string) { | ||
var FOO64 = b64.fromByteArray(FOO) | ||
var BAR64 = b64.fromByteArray(BAR) | ||
var BAZ64 = b64.fromByteArray(BAZ) | ||
var FOO64 = to(FOO, 'base64') | ||
var BAR64 = to(BAR, 'base64') | ||
var BAZ64 = to(BAZ, 'base64') | ||
var FOOx = u.toHex('foo') | ||
@@ -38,0 +38,0 @@ var BARx = u.toHex('bar') |
@@ -6,4 +6,4 @@ exports.write = write | ||
exports.Uint32toHex = Uint32toHex | ||
exports.toString = toString | ||
var bopsToString = require('bops/typedarray/to') | ||
//change me: args should be: | ||
@@ -88,1 +88,6 @@ //buffer, string, enc, string_start, buffer_start | ||
function toString(buf, enc) { | ||
if(null == enc) return 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20511
13
592
0
31
1
+ Addedbops@~0.1.1
+ Addedbase64-js@0.0.2(transitive)
+ Addedbops@0.1.1(transitive)
+ Addedto-utf8@0.0.1(transitive)