From: Chris Duncan Date: Tue, 26 Nov 2024 19:42:28 +0000 (-0800) Subject: Replace deprecated assert calls with if-throw statements. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=be57b2e00f8d30e0318fb18a8ddecfb8192388ec;p=libnemo.git Replace deprecated assert calls with if-throw statements. --- diff --git a/src/lib/blake2b.ts b/src/lib/blake2b.ts index cd5d054..2e797c0 100644 --- a/src/lib/blake2b.ts +++ b/src/lib/blake2b.ts @@ -222,15 +222,18 @@ function Blake2b (outlen, key, salt, personal) { } 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 @@ -288,20 +291,29 @@ var Proto = Blake2b 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) } }