Digest interfacev0.1.0
pub interface Digest {
func Update(self: &var Self, bytes: char8[..]);
func Finish(self: &var Self, into: var char8[..]);
func DigestLength(self: &Self) -> uint;
func BlockLength(self: &Self) -> uint;
}
Take one by generic bound and mutable reference — func Sum<D: Digest>(digest: &var D) — so work applies to
the caller's state without copying it.
Requirements
Update
func Update(self: &var Self, bytes: char8[..])
Adds bytes to what is being hashed.
Any split of the same byte sequence across any number of calls gives the same digest. An empty slice is
legal and changes nothing.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to absorb |
Finish
func Finish(self: &var Self, into: var char8[..])
Writes the digest into into and leaves the state unusable for further updates.
into must be at least DigestLength bytes; anything beyond that is untouched. Finishing twice is a
caller error rather than a supported operation — a digest is a one-shot summary of everything fed to it,
and an implementation is free to consume its state producing one.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | receives the output |
DigestLength
func DigestLength(self: &Self) -> uint
How many bytes Finish writes.
Returns: how many bytes a digest occupies
BlockLength
func BlockLength(self: &Self) -> uint
How many bytes the algorithm processes at a time. Needed by the constructions built on digests — HMAC pads its key to exactly this — and by callers choosing a buffer size that avoids splitting work.
Returns: how many bytes the compression function consumes at a time