mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
Hash.update and Hmac.update accept every Buffer input encoding and any TypedArray or DataView. Hex input of odd length throws Node's ERR_INVALID_ARG_VALUE, an encoding Node does not know reads as UTF-8, and data of other types throws ERR_INVALID_ARG_TYPE. digest() returns a string for every Buffer encoding and a Buffer for a falsy or unknown one, and a repeated Hmac.digest() returns Node's empty result. createHash and hash.copy take options.outputLength for the SHAKE and KECCAK-KMAC digests, with Node 24.22's validation and its ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH error, including the library and reason properties, for other digests. crypto.hash takes an output encoding or an options object with outputEncoding (including "buffer") and outputLength. The functionName and customization options are validated and then refused with Node 24.22's errors. createHmac takes TypedArray, DataView and ArrayBuffer keys and options.encoding for string keys, and checks them in Node's order. Calls whose encodings and options the compiler can resolve keep their typed fast paths. Other forms go through runtime entry points that apply Node's checks and return a string or Buffer, checked at the call's type. A literal digest encoding for which Node returns a Buffer is refused when the declared result is a string. The digest compression functions start on a cache line, so their speed no longer depends on the size of unrelated runtime code.