abstract class Digest
inherits Reference
¶
Digest
is the base type of hashing algorithms like Digest::MD5
,
Digest::SHA1
, Digest::SHA256
, or Digest::SHA512
.
A Digest
instance holds the state of an ongoing hash calculation.
It can receive new data to include in the hash via #update
, #<<
, or #file
.
Once all data is included, use #final
to get the hash. This will mark the
ongoing calculation as finished. A finished calculation can't receive new data.
A digest.dup.final
call may be used to get an intermediate hash value.
Use #reset
to reuse the Digest
instance for a new calculation.
Direct known subclasses
Crystal::Digest::MD5
OpenSSL::Digest
Methods¶
#file(file_name : Path | String) : self
¶
(file_name : Path | String) : self
Reads the file's content and updates the digest with it.
#final : Bytes
¶
: Bytes
Returns the final digest output.
This method can only be called once and raises FinalizedError
on subsequent calls.
Note
.dup.final
call may be used to get an intermediate hash value.
abstract
#final_impl(dst : Bytes) : Nil
¶
(dst : Bytes) : Nil
Stores the output digest of #digest_size bytes in dst.