class

Digest

Inherits Reference / Object

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 or #hexfinal 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.

Instance methods

<<(data) : self

Reads the io's data and updates the digest with it.

Source
digest_size

Returns the digest output size in bytes.

Source
file(file_name : Path | String) : self

Reads the file's content and updates the digest with it.

Source
final(dst : Bytes) : Bytes

Puts the final digest output into dst.

Faster than the Bytes allocating version. Use when hashing in loops.

final or hexfinal can only be called once and raises FinalizedError on subsequent calls.

NOTE: .dup.final(dst) call may be used to get an intermediate hash value.

Source
final

Returns the final digest output.

final or hexfinal can only be called once and raises FinalizedError on subsequent calls.

NOTE: .dup.final call may be used to get an intermediate hash value.

Source
final_impl(dst : Bytes) : Nil

Stores the output digest of #digest_size bytes in dst.

Source
hexfinal(dst : Bytes) : Nil

Writes a hexadecimal-encoded digest to dst.

Faster than the String allocating version. Use when hashing in loops.

final or hexfinal can only be called once and raises FinalizedError on subsequent calls.

NOTE: .dup.final call may be used to get an intermediate hash value.

Source
hexfinal(io : IO) : Nil

Writes a hexadecimal-encoded digest to IO.

Faster than the String allocating version.

final or hexfinal can only be called once and raises FinalizedError on subsequent calls.

NOTE: .dup.final call may be used to get an intermediate hash value.

This method is restricted to a maximum digest size of 64 bytes. Implementations that allow a larger digest size should override this method to use a larger buffer.

Source
hexfinal

Returns a hexadecimal-encoded digest in a new String.

final or hexfinal can only be called once and raises FinalizedError on subsequent calls.

NOTE: .dup.hexfinal call may be used to get an intermediate hash value.

Source
reset

Resets the state of this object. Use to get another hash value without creating a new object.

Source
reset_impl

Resets the object to it's initial state.

Source
update(data : Bytes) : self
Source
update(io : IO) : self

Reads the io's data and updates the digest with it.

Source
update(data) : self
Source
update_impl(data : Bytes) : Nil

Hashes data incrementally.

Source

Nested types