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 Bytes: FromHex + Copy;

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

    // Required methods
    fn from_engine(e: Self::Engine) -> Self;
    fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>;
    fn to_byte_array(self) -> Self::Bytes;
    fn as_byte_array(&self) -> &Self::Bytes;
    fn from_byte_array(bytes: Self::Bytes) -> Self;
    fn all_zeros() -> Self;

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

Trait which applies to hashes of all types.

Required Associated Types§

source

type Engine: HashEngine

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.

source

type Bytes: FromHex + Copy

The byte array that represents the hash internally.

Required Associated Constants§

source

const LEN: usize

Length of the hash, in bytes.

Provided Associated Constants§

source

const DISPLAY_BACKWARD: bool = false

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§

source

fn from_engine(e: Self::Engine) -> Self

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

source

fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>

Copies a byte slice into a hash object.

source

fn to_byte_array(self) -> Self::Bytes

Returns the underlying byte array.

source

fn as_byte_array(&self) -> &Self::Bytes

Returns a reference to the underlying byte array.

source

fn from_byte_array(bytes: Self::Bytes) -> Self

Constructs a hash from the underlying byte array.

source

fn all_zeros() -> Self

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§

source

fn engine() -> Self::Engine

Constructs a new engine.

source

fn hash(data: &[u8]) -> Self

Hashes some bytes.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Hash for groestlcoin_hashes::groestld::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

source§

const LEN: usize = 32usize

source§

const DISPLAY_BACKWARD: bool = true

source§

impl Hash for groestlcoin_hashes::hash160::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

source§

const LEN: usize = 20usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::ripemd160::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

source§

const LEN: usize = 20usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::sha1::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

source§

const LEN: usize = 20usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::sha256::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

source§

const LEN: usize = 32usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::sha256d::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

source§

const LEN: usize = 32usize

source§

const DISPLAY_BACKWARD: bool = true

source§

impl Hash for groestlcoin_hashes::sha512::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 64]

source§

const LEN: usize = 64usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::sha512_256::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

source§

const LEN: usize = 32usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl Hash for groestlcoin_hashes::siphash24::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 8]

source§

const LEN: usize = 8usize

source§

const DISPLAY_BACKWARD: bool = false

source§

impl<T: Tag> Hash for groestlcoin_hashes::sha256t::Hash<T>

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

source§

const LEN: usize = 32usize

source§

const DISPLAY_BACKWARD: bool = true

source§

impl<T: Hash> Hash for Hmac<T>

§

type Engine = HmacEngine<T>

§

type Bytes = <T as Hash>::Bytes

source§

const LEN: usize = T::LEN