function digest (out?: 'binary' | Uint8Array): Uint8Array
function digest (out?: 'binary' | 'hex' | Uint8Array): string | Uint8Array {
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(outlen) : out
- if (!(buf instanceof Uint8Array))
- throw new TypeError(`out must be "binary", "hex", Uint8Array, or Buffer`)
- if (buf.length < outlen)
- throw new RangeError(`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 < outlen) throw new RangeError(`out must have at least outlen bytes of space`)
blake2bFinal(this, buf)
if (out === 'hex') return hexSlice(buf)
return buf
const toHex = function (n: number) {
if (typeof n !== 'number')
- throw new TypeError(`expected number to convert to hex, received convert ${typeof n}`)
+ throw new TypeError(`expected number to convert to hex; received ${typeof n}`)
if (n < 0 || n > 255)
- throw new RangeError(`expected byte value 0-255, received ${n}`)
+ throw new RangeError(`expected byte value 0-255; received ${n}`)
return n.toString(16).padStart(2, '0')
}
// finally execute the original function call
if (noAssert !== true) {
- 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 (outlen < BYTES_MIN) throw new RangeError(`expected outlen >= ${BYTES_MIN}; actual ${outlen}`)
+ if (outlen > BYTES_MAX) throw new RangeError(`expectd outlen <= ${BYTES_MAX}; actual ${outlen}`)
if (key != null) {
- 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 (!(key instanceof Uint8Array)) throw new TypeError(`key must be Uint8Array or Buffer`)
+ if (key.length < KEYBYTES_MIN) throw new RangeError(`expected key >= ${KEYBYTES_MIN}; actual ${key.length}`)
+ if (key.length > KEYBYTES_MAX) throw new RangeError(`expected key <= ${KEYBYTES_MAX}; actual ${key.length}`)
}
if (salt != null) {
- 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 (!(salt instanceof Uint8Array)) throw new TypeError(`salt must be Uint8Array or Buffer`)
+ if (salt.length !== SALTBYTES) throw new RangeError(`expected salt ${SALTBYTES} bytes; actual ${salt.length} bytes`)
}
if (personal != null) {
- 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}`)
+ if (!(personal instanceof Uint8Array)) throw new TypeError(`personal must be Uint8Array or Buffer`)
+ if (personal.length !== PERSONALBYTES) throw new RangeError(`expected personal ${PERSONALBYTES} bytes; actual ${personal.length} bytes`)
}
}