}
Blake2b.prototype.update = function (input) {
- assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer')
+ if (!(input instanceof Uint8Array))
+ throw new TypeError('input must be Uint8Array or Buffer')
blake2bUpdate(this, input)
return this
}
Blake2b.prototype.digest = function (out) {
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out
- assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer')
- assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space')
+ if (!(buf instanceof Uint8Array))
+ throw new TypeError('out must be "binary", "hex", Uint8Array, or Buffer')
+ if (buf.length < this.outlen)
+ throw new RangeError('out must have at least outlen bytes of space')
blake2bFinal(this, buf)
if (out === 'hex') return hexSlice(buf)
return buf
module.exports = function createHash (outlen, key, salt, personal, noAssert) {
if (noAssert !== true) {
- assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen)
- assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen)
+ if (outlen < BYTES_MIN)
+ throw new RangeError('outlen must be at least ' + BYTES_MIN + ', was given ' + outlen)
+ if (outlen > BYTES_MAX)
+ throw new RangeError('outlen must be at most ' + BYTES_MAX + ', was given ' + outlen)
if (key != null) {
- assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer')
- assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length)
- assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length)
+ if (!(key instanceof Uint8Array))
+ throw new TypeError('key must be Uint8Array or Buffer')
+ if (key.length < KEYBYTES_MIN)
+ throw new RangeError('key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length)
+ if (key.length > KEYBYTES_MAX)
+ throw new RangeError('key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length)
}
if (salt != null) {
- assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer')
- assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length)
+ if(!(salt instanceof Uint8Array))
+ throw new TypeError('salt must be Uint8Array or Buffer')
+ if (salt.length !== SALTBYTES)
+ throw new RangeError('salt must be exactly ' + SALTBYTES + ', was given ' + salt.length)
}
if (personal != null) {
- assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer')
- assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length)
+ if(!(personal instanceof Uint8Array))
+ throw new TypeError( 'personal must be Uint8Array or Buffer')
+ if(personal.length !== PERSONALBYTES)
+ throw new RangeError('personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length)
}
}