hkdf

Trait BitcoinHash

pub trait BitcoinHash:
    Copy
    + Clone
    + PartialEq
    + Eq
    + PartialOrd
    + Ord
    + Hash
    + Debug
    + Display
    + LowerHex
    + Index<RangeFull, Output = [u8], Output = [u8], Output = [u8], Output = [u8], Output = u8>
    + Index<RangeFrom<usize>>
    + Index<RangeTo<usize>>
    + Index<Range<usize>>
    + Index<usize>
    + 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 { ... }
    fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
       where B: AsRef<[u8]>,
             I: IntoIterator<Item = B> { ... }
}
Expand description

Trait which applies to hashes of all types.

Required Associated Constants§

const LEN: usize

Length of the hash, in bytes.

Provided Associated Constants§

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 Associated Types§

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.

type Bytes: FromHex + Copy

The byte array that represents the hash internally.

Required Methods§

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

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

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

Copies a byte slice into a hash object.

fn to_byte_array(self) -> Self::Bytes

Returns the underlying byte array.

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

Returns a reference to the underlying byte array.

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

Constructs a hash from the underlying byte array.

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§

fn engine() -> Self::Engine

Constructs a new engine.

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

Hashes some bytes.

fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
where B: AsRef<[u8]>, I: IntoIterator<Item = B>,

Hashes all the byte slices retrieved from the iterator together.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl Hash for hkdf::hashes::Hash160

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

impl Hash for hkdf::hashes::Ripemd160

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

impl Hash for hkdf::hashes::Sha1

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

impl Hash for hkdf::hashes::Sha256

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

impl Hash for hkdf::hashes::Sha256d

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

impl Hash for hkdf::hashes::Sha512

§

const LEN: usize = 64usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 64]

§

impl Hash for hkdf::hashes::Siphash24

§

const LEN: usize = 8usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 8]

§

impl Hash for Hash

§

const LEN: usize = 48usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 48]

§

impl Hash for Hash

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

impl<T> Hash for Hash<T>
where T: Tag,

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

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

§

const LEN: usize = T::LEN

§

type Engine = HmacEngine<T>

§

type Bytes = <T as Hash>::Bytes