Browse Source

fix minor bugs. /cc @emilbayes

master
Mathias Buus 7 years ago
parent
commit
db42eaf54b
  1. 5
      README.md
  2. 6
      index.js
  3. 2
      test.js

5
README.md

@ -44,6 +44,11 @@ Update the hash with a new piece of data. `data` should be a buffer or uint8arra
Digest the hash.
#### `var promise = blake2b.ready([cb])`
Wait for the WASM code to load. Returns the WebAssembly instance promise as well for convenience.
You have to call this at least once before instantiating the hash.
## Browser demo
There is a browser example included in [example.html](example.html) and [example.js](example.js).

6
index.js

@ -19,8 +19,10 @@ var SALTBYTES = module.exports.SALTBYTES = 16
var PERSONALBYTES = module.exports.PERSONALBYTES = 16
function Blake2b (digestLength, key, salt, personal, noAssert) {
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal)
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
if (!mod) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
if (!digestLength) digestLength = 32
if (noAssert !== true) {
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength)
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength)
@ -35,7 +37,7 @@ function Blake2b (digestLength, key, salt, personal, noAssert) {
head += 216
}
this.digestLength = digestLength || 32
this.digestLength = digestLength
this.finalized = false
this.pointer = freeList.pop()

2
test.js

@ -53,7 +53,7 @@ blake2b.ready(function () {
var salt = vector.salt && Buffer.from(vector.salt, 'hex')
var personal = vector.personal && Buffer.from(vector.personal, 'hex')
var hash = blake2b(vector.outlen, key, salt, personal)
var hash = blake2b(vector.outlen, key, salt, personal, true)
.update(Buffer.from(vector.input, 'hex'))
.digest('hex')

Loading…
Cancel
Save