Go to Latest
class crypto.DigestContext
import { crypto } from "https://deno.land/std@0.116.0/_wasm_crypto/mod.ts";
const { DigestContext } = crypto;

A context for incrementally computing a digest using a given hash algorithm.

Constructors

new
DigestContext(algorithm)

Creates a new context incrementally computing a digest using the given hash algorithm.

An error will be thrown if algorithm is not a supported hash algorithm.

Methods

Returns a new DigestContext that is a copy of this one, i.e., using the same algorithm and with a copy of the same internal state.

This may be a more efficient option for computing multiple digests that start with a common prefix.

digest(length)

Returns the digest of the input data so far. This may be called repeatedly without side effects.

length will usually be left undefined to use the default length for the algorithm. For algorithms with variable-length output, it can be used to specify a non-negative integer number of bytes.

An error will be thrown if algorithm is not a supported hash algorithm or length is not a supported length for the algorithm.

Returns the digest of the input data so far, and then drops the context from memory on the WASM side. This context must no longer be used, and any further method calls will result in null pointer errors being thrown. https://github.com/rustwasm/wasm-bindgen/blob/bf39cfd8/crates/backend/src/codegen.rs#L186

length will usually be left undefined to use the default length for the algorithm. For algorithms with variable-length output, it can be used to specify a non-negative integer number of bytes.

An error will be thrown if algorithm is not a supported hash algorithm or length is not a supported length for the algorithm.

Returns the digest of the input data so far, and resets this context to its initial state, as though it has not yet been provided with any input data. (It will still use the same algorithm.)

length will usually be left undefined to use the default length for the algorithm. For algorithms with variable-length output, it can be used to specify a non-negative integer number of bytes.

An error will be thrown if algorithm is not a supported hash algorithm or length is not a supported length for the algorithm.

Resets this context to its initial state, as though it has not yet been provided with any input data. (It will still use the same algorithm.)

update(data)

Update the digest's internal state with the additional input data.

If the data array view is large, it will be split into subarrays (via JavaScript bindings) which will be processed sequentially in order to limit the amount of memory that needs to be allocated in the WASM heap.