Adler64Base Class
Definition
Provides a reusable base class for Adler-64 style checksum algorithms using ulong
accumulators.
public abstract class Adler64Base : Adler<ulong>, IResumableHashAlgorithm
- Inheritance
-
Adler64Base
- Implements
- Derived
- Inherited Members
- Extension Methods
-
NonCryptographicHashAlgorithmExtensions.ComputeHash(NonCryptographicHashAlgorithm, byte[], int, int)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], byte[])NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], string)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, Stream, byte[])
Examples
// Consume through a concrete derivative - the shared 64-bit finalization layout
// is identical across every Adler64Base subclass.
Adler64Base hash = new Adler64();
hash.Append("Wikipedia"u8);
byte[] digest = hash.GetCurrentHash(); // big-endian (B << 32) | A
Remarks
Finalization combines the A and B accumulators into a 64-bit hash as (B << 32) | A, written in
big-endian byte order.
Constructors
Adler64Base(ulong)
Initializes a new instance of the Adler64Base class with the specified modulus.
protected Adler64Base(ulong modulo)
Parameters
moduloulongThe modulus applied to the accumulators after each reduction step.
Methods
GetCurrentHashCore(Span<byte>)
When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.
protected override void GetCurrentHashCore(Span<byte> destination)
Parameters
TryComputeHashFrom(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, out int)
Resumes a hash computation from a previously finalized hash value, processes additional input, and writes the new finalized hash to the specified destination span.
public bool TryComputeHashFrom(ReadOnlySpan<byte> previousHash, ReadOnlySpan<byte> newData, Span<byte> destination, out int bytesWritten)
Parameters
previousHashReadOnlySpan<byte>The previously finalized hash value to resume from.
newDataReadOnlySpan<byte>The additional input data to include in the resumed hash calculation.
destinationSpan<byte>The destination buffer to write the finalized hash value to.
bytesWrittenintOutputs the number of bytes written to the destination buffer.
Returns
- bool
true if the resumed and finalized hash was written successfully; otherwise, false if the destination span was too small.
Remarks
Adler digests carry the complete accumulator state ((B << 32) | A, big-endian), so resuming
requires no finalization reversal: the halves seed the accumulators directly. The computation runs against
saved-and-restored instance state, so any in-progress incremental state on the instance survives the call
unchanged.
Exceptions
- ArgumentException
Thrown if the
previousHashlength does not match HashLengthInBytes.
Explicit Interface Implementations
IResumableHashAlgorithm.get_HashLengthInBytes()
int IResumableHashAlgorithm.get_HashLengthInBytes()
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |