EvpDigest class

An incremental (streaming) message digest.

Wraps an EVP_MD_CTX so a digest can be computed over input that arrives in pieces — a file read chunk by chunk, a socket, an HTTP body — without ever holding the whole input in memory. Native memory stays bounded by bufferSize no matter how large the input or the individual chunks are. For data already in memory, OpenSSL.digest is simpler.

Create it with OpenSSL.startDigest, feed it with add or addStream, and read the result with finish. copy forks the state, for inputs that share a prefix. finish releases the native context on success; dispose releases it on any other path, so call it from a finally — it is idempotent and safe to call after finish. A digest that is garbage collected without either call is still released, by finalizer, but that is a safety net rather than something to rely on.

final digest = openSsl.startDigest('sha256');
try {
  await digest.addStream(File('report.pdf').openRead());
  print('${digest.length} bytes -> ${digest.finish()}');
} finally {
  digest.dispose();
}

An instance is not safe for concurrent use: it owns one scratch buffer and one native context. Use one instance per computation. It is also bound to the isolate that created it — like the OpenSslContext it came from, its native pointers cannot be sent anywhere else.

Implemented types

Constructors

EvpDigest(OpenSslContext context, String algorithmName, {int bufferSize = defaultBufferSize})
Starts a digest with algorithmName, as named by OpenSSL — sha256, sha512, sha3-256, sha1, … (the DigestAlgorithm constants are these names, spell-checked by the compiler).
factory

Properties

algorithmName → String
The digest algorithm being computed, as given to the constructor.
final
bufferSize → int
Size of the scratch buffer handed to OpenSSL, in bytes.
final
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether the native resources have been released.
no setter
isFinished → bool
Whether finish has already produced the digest.
no setter
length → int
Number of bytes fed so far.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(List<int> data) → void
Feeds data into the digest.
addStream(Stream<List<int>> data) → Future<void>
Feeds everything data emits, in order, and completes when it closes.
copy() → EvpDigest
Forks the digest: a new EvpDigest with the same algorithm, buffer size, length and internal state, which evolves on its own from here on.
dispose() → void
Releases the native context and scratch buffer.
finish() → Uint8List
Produces the digest and releases the native context.
finishHex() → String
Produces the digest as lowercase hexadecimal, and releases the context.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultBufferSize → const int
Default scratch buffer size: 64 KiB, the chunk size File.openRead uses.