*
* @param {Uint8Array} out - Buffer to store the final output
*/
- #blake2bFinal (out: Uint8Array): void {
+ #blake2bFinal (out: Uint8Array<ArrayBuffer>): void {
this.#t += BigInt(this.#c) // add final message block size to total bytes
this.#b.fill(0, this.#c) // pad final block with zeros
this.#blake2bCompress(true) // set final block flag and compress
digest (): Uint8Array<ArrayBuffer>
digest (out: 'hex'): string
digest (out: 'binary' | Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>
- digest (out?: 'binary' | 'hex' | Uint8Array<ArrayBuffer>): string | Uint8Array<ArrayBuffer> {
- const buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.#outlen) : out
- if (!(buf instanceof Uint8Array)) throw new TypeError('out must be "binary", "hex", Uint8Array, or Buffer')
+ digest (out?: unknown): string | Uint8Array<ArrayBuffer> {
+ if (out !== undefined && out !== 'binary' && out !== 'hex' && !(out instanceof Uint8Array)) {
+ throw new TypeError('out must be "binary", "hex", Uint8Array, or Buffer')
+ }
+ const buf = (out === undefined || typeof out === 'string') ? new Uint8Array(this.#outlen) : new Uint8Array(out)
if (buf.length < this.#outlen) throw new RangeError('out must have at least outlen bytes of space')
this.#blake2bFinal(buf)
return (out === 'hex')