finish method
Produces the digest and releases the native context.
The result is length bytes of input reduced to the algorithm's output
size — 32 bytes for sha256. Calling it twice throws StateError: an
EVP_MD_CTX cannot be finalized more than once.
Implementation
Uint8List finish() {
_ensureUsable();
final out = malloc<UnsignedChar>(_maxDigestSize);
final outLen = malloc<UnsignedInt>();
try {
if (_bindings.EVP_DigestFinal_ex(_ctx, out, outLen) != 1) {
throw OpenSslException('EVP_DigestFinal_ex failed');
}
final digest =
Uint8List.fromList(out.cast<Uint8>().asTypedList(outLen.value));
_finished = true;
_release();
return digest;
} finally {
malloc.free(out);
malloc.free(outLen);
}
}