Skip to main content

Hasher

Struct Hasher 

Source
pub struct Hasher<const BITS: usize>(/* private fields */);
Expand description

handy method to create a hash of given SIZE bit size.

The hash algorithm is Blake2b and the constant parameter is the number of bits to generate. Good values are 256 or 224 for Cardano.

§Generate a cryptographic hash with Blake2b 256

The following will generate a 32 bytes digest output


let mut hasher = Hasher::<256>::new();
hasher.input(b"My transaction");

let digest = hasher.finalize();

§Generate a cryptographic hash with Blake2b 224

The following will generate a 28 bytes digest output. This is used to generate the hash of public keys for addresses.


let digest = Hasher::<224>::hash(b"My Public Key");

Implementations§

Source§

impl<const BITS: usize> Hasher<BITS>

Source

pub fn input(&mut self, bytes: &[u8])

update the Hasher with the given inputs

Source§

impl Hasher<160>

Source

pub fn new() -> Hasher<160>

create a new Hasher

Source

pub fn hash( bytes: &[u8], ) -> Hash<pallas_crypto::::hash::hasher::{impl#2}::hash::{constant#0}>

convenient function to directly generate the hash of the given bytes without creating the intermediary types Hasher and calling Hasher::input.

Source

pub fn hash_tagged( bytes: &[u8], tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#2}::hash_tagged::{constant#0}>

Source

pub fn hash_cbor( data: &impl Encode<()>, ) -> Hash<pallas_crypto::::hash::hasher::{impl#2}::hash_cbor::{constant#0}>

convenient function to directly generate the hash of the given minicbor::Encode data object

Source

pub fn hash_tagged_cbor( data: &impl Encode<()>, tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#2}::hash_tagged_cbor::{constant#0}>

Source

pub fn finalize( self, ) -> Hash<pallas_crypto::::hash::hasher::{impl#2}::finalize::{constant#0}>

consume the Hasher and returns the computed digest

Source§

impl Hasher<224>

Source

pub fn new() -> Hasher<224>

create a new Hasher

Source

pub fn hash( bytes: &[u8], ) -> Hash<pallas_crypto::::hash::hasher::{impl#4}::hash::{constant#0}>

convenient function to directly generate the hash of the given bytes without creating the intermediary types Hasher and calling Hasher::input.

Source

pub fn hash_tagged( bytes: &[u8], tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#4}::hash_tagged::{constant#0}>

Source

pub fn hash_cbor( data: &impl Encode<()>, ) -> Hash<pallas_crypto::::hash::hasher::{impl#4}::hash_cbor::{constant#0}>

convenient function to directly generate the hash of the given minicbor::Encode data object

Source

pub fn hash_tagged_cbor( data: &impl Encode<()>, tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#4}::hash_tagged_cbor::{constant#0}>

Source

pub fn finalize( self, ) -> Hash<pallas_crypto::::hash::hasher::{impl#4}::finalize::{constant#0}>

consume the Hasher and returns the computed digest

Source§

impl Hasher<256>

Source

pub fn new() -> Hasher<256>

create a new Hasher

Source

pub fn hash( bytes: &[u8], ) -> Hash<pallas_crypto::::hash::hasher::{impl#6}::hash::{constant#0}>

convenient function to directly generate the hash of the given bytes without creating the intermediary types Hasher and calling Hasher::input.

Source

pub fn hash_tagged( bytes: &[u8], tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#6}::hash_tagged::{constant#0}>

Source

pub fn hash_cbor( data: &impl Encode<()>, ) -> Hash<pallas_crypto::::hash::hasher::{impl#6}::hash_cbor::{constant#0}>

convenient function to directly generate the hash of the given minicbor::Encode data object

Source

pub fn hash_tagged_cbor( data: &impl Encode<()>, tag: u8, ) -> Hash<pallas_crypto::::hash::hasher::{impl#6}::hash_tagged_cbor::{constant#0}>

Source

pub fn finalize( self, ) -> Hash<pallas_crypto::::hash::hasher::{impl#6}::finalize::{constant#0}>

consume the Hasher and returns the computed digest

Trait Implementations§

Source§

impl Default for Hasher<160>

Source§

fn default() -> Hasher<160>

Returns the “default value” for a type. Read more
Source§

impl Default for Hasher<224>

Source§

fn default() -> Hasher<224>

Returns the “default value” for a type. Read more
Source§

impl Default for Hasher<256>

Source§

fn default() -> Hasher<256>

Returns the “default value” for a type. Read more
Source§

impl<const BITS: usize> Write for &mut Hasher<BITS>

Source§

type Error = Infallible

Source§

fn write_all( &mut self, buf: &[u8], ) -> Result<(), <&mut Hasher<BITS> as Write>::Error>

Write the whole byte slice.

Auto Trait Implementations§

§

impl<const BITS: usize> Freeze for Hasher<BITS>

§

impl<const BITS: usize> RefUnwindSafe for Hasher<BITS>

§

impl<const BITS: usize> Send for Hasher<BITS>

§

impl<const BITS: usize> Sync for Hasher<BITS>

§

impl<const BITS: usize> Unpin for Hasher<BITS>

§

impl<const BITS: usize> UnsafeUnpin for Hasher<BITS>

§

impl<const BITS: usize> UnwindSafe for Hasher<BITS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.