HashFunction

Incremental hash function that accumulates data and produces a digest on finalization.

Data is fed via update and the digest is obtained by calling one of the finalization methods: hashIntoByteArray, hashToByteArray, or hash. After finalization, the function can be reset and reused, or closed to release resources.

Obtained via Hasher.createHashFunction.

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
open fun hash(): ByteString

Finalizes the hash computation and returns the result as a ByteString.

Link copied to clipboard
abstract fun hashIntoByteArray(destination: ByteArray, destinationOffset: Int = 0): Int

Finalizes the hash computation and writes the result into destination starting at destinationOffset, and returns the number of bytes written.

Link copied to clipboard
abstract fun hashToByteArray(): ByteArray

Finalizes the hash computation and returns the result as a new ByteArray.

Link copied to clipboard
abstract fun reset()

Resets the accumulated state, allowing this function to be reused for a new operation without creating a new instance.

Link copied to clipboard
open fun update(source: RawSource)

Reads all available data from the source and feeds it into this function.

abstract fun update(source: ByteArray, startIndex: Int = 0, endIndex: Int = source.size)

Feeds data from the source byte array into this function. Only the portion from startIndex (inclusive) to endIndex (exclusive) is processed.

open fun update(source: ByteString, startIndex: Int = 0, endIndex: Int = source.size)

Feeds data from the source byte string into this function. Only the portion from startIndex (inclusive) to endIndex (exclusive) is processed.

Link copied to clipboard
open fun updatingSink(sink: RawSink): RawSink

Returns a RawSink wrapper around the given sink that feeds all data written through it into this function as a side effect. Useful for writing data to a sink while simultaneously computing a hash or signature.

Link copied to clipboard

Returns a RawSource wrapper around the given source that feeds all data read through it into this function as a side effect. Useful for processing data from a source while simultaneously computing a hash or signature.