std.crypto.hash.Hash
class pub Hash
The output of a cryptographic or (cryptography related) universal hash function.
Unlike std.hash.Hash
, this type is produced by hashers rather than a
trait to implement. In addition it's aimed at hasher related to cryptography,
such as SHA256 and Poly1305. This type isn't suitable for hashing arbitrary
Inko types.
Fields
bytes
let pub @bytes: ByteArray
The bytes that make up this Hash.
Static methods
new
Show source codeHide source code
fn pub static new(bytes: ByteArray) -> Hash {
Hash(bytes)
}
fn pub static new(bytes: ByteArray) -> Hash
Returns a new empty Digest
.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: T) -> Bool {
(self == other).false?
}
fn pub !=(other: T) -> Bool
Returns true
if self
and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: ref Hash) -> Bool {
@bytes == other.bytes
}
fn pub ==(other: ref Hash) -> Bool
Returns true
if self
and the given object are equal to each other.
This operator is used to perform structural equality. This means two objects residing in different memory locations may be considered equal, provided their structure is equal. For example, two different arrays may be considered to have structural equality if they contain the exact same values.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
formatter.write(to_string)
}
fn pub fmt(formatter: mut Formatter)
Formats self
in a human-readable format for debugging purposes.
to_string
Show source codeHide source code
fn pub to_string -> String {
# We don't use Int.format here because we need extra padding, and to avoid
# allocating a String for every byte.
let hex = ByteArray.filled(with: 0, times: @bytes.size * 2)
@bytes.iter.each_with_index(fn (index, byte) {
let hex_index = index * 2
hex.set(hex_index, HEX_DIGITS.byte(byte >> 4))
hex.set(hex_index + 1, HEX_DIGITS.byte(byte & 0x0F))
})
hex.into_string
}
fn pub to_string -> String
Returns a hexadecimal String
of this digest.
Implemented traits
Equal
impl Equal[ref Hash] for Hash
Format
impl Format for Hash
ToString
impl ToString for Hash