pub trait Hash: Copy + Clone + PartialEq + Eq + PartialOrd + Ord + Hash + Debug + Display + LowerHex + Index<RangeFull, Output = [u8]> + Index<RangeFrom<usize>, Output = [u8]> + Index<RangeTo<usize>, Output = [u8]> + Index<Range<usize>, Output = [u8]> + Index<usize, Output = u8> + Borrow<[u8]> {
    type Engine: HashEngine;
    type Inner: FromHex;

    const LEN: usize;
    const DISPLAY_BACKWARD: bool = false;

    fn from_engine(e: Self::Engine) -> Self;
    fn from_slice(sl: &[u8]) -> Result<Self, Error>;
    fn into_inner(self) -> Self::Inner;
    fn as_inner(&self) -> &Self::Inner;
    fn from_inner(inner: Self::Inner) -> Self;
    fn all_zeros() -> Self;

    fn engine() -> Self::Engine { ... }
    fn hash(data: &[u8]) -> Self { ... }
}
Expand description

Trait which applies to hashes of all types.

Required Associated Types

A hashing engine which bytes can be serialized into. It is expected to implement the io::Write trait, and to never return errors under any conditions.

The byte array that represents the hash internally.

Required Associated Constants

Length of the hash, in bytes.

Provided Associated Constants

Flag indicating whether user-visible serializations of this hash should be backward. For some reason Satoshi decided this should be true for Sha256dHash, so here we are.

Required Methods

Produces a hash from the current state of a given engine.

Copies a byte slice into a hash object.

Unwraps the hash and returns the underlying byte array.

Unwraps the hash and returns a reference to the underlying byte array.

Constructs a hash from the underlying byte array.

Returns an all zero hash.

An all zeros hash is a made up construct because there is not a known input that can create it, however it is used in various places in Bitcoin e.g., the Bitcoin genesis block’s previous blockhash and the coinbase transaction’s outpoint txid.

Provided Methods

Constructs a new engine.

Hashes some bytes.

Implementors