Struct win_crypto_ng::hash::Hash

source ·
pub struct Hash { /* private fields */ }
Expand description

Hashing operation

Implementations§

source§

impl Hash

source

pub fn hash(&mut self, data: &[u8]) -> Result<()>

Perform a one way hash on the data

This method can be called multiple times. To get the final result, use finish.

Examples
let algo = HashAlgorithm::open(HashAlgorithmId::Sha256).unwrap();
let mut hash = algo.new_hash().unwrap();
hash.hash("Some data".as_bytes()).unwrap();
hash.hash("Some more data".as_bytes()).unwrap();
source

pub fn finish(self) -> Result<Buffer>

Get the hash value

This method consumes the hash operation. To create a new hash, a new instance must be created.

Examples
let algo = HashAlgorithm::open(HashAlgorithmId::Sha256).unwrap();
let mut hash = algo.new_hash().unwrap();
hash.hash("Some data".as_bytes()).unwrap();
let result = hash.finish().unwrap();

assert_eq!(result.as_slice(), [
    0x1F, 0xE6, 0x38, 0xB4, 0x78, 0xF8, 0xF0, 0xB2,
    0xC2, 0xAA, 0xB3, 0xDB, 0xFD, 0x3F, 0x05, 0xD6,
    0xDf, 0xE2, 0x19, 0x1C, 0xD7, 0xB4, 0x48, 0x22,
    0x41, 0xFE, 0x58, 0x56, 0x7E, 0x37, 0xAE, 0xF6,
]);
source

pub fn hash_size(&self) -> Result<usize>

Get the final hash length, in bytes.

Examples
let algo = HashAlgorithm::open(HashAlgorithmId::Sha256).unwrap();
let hash = algo.new_hash().unwrap();
let hash_size = hash.hash_size().unwrap();

assert_eq!(hash_size, 32);
source

pub fn hash_algorithm(&self) -> Result<HashAlgorithmId>

Get the hash algorithm used for this hash object.

Examples
let algo = HashAlgorithm::open(HashAlgorithmId::Sha256).unwrap();
let hash = algo.new_hash().unwrap();

assert_eq!(hash.hash_algorithm().unwrap(), HashAlgorithmId::Sha256);

Trait Implementations§

source§

impl Clone for Hash

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Hash

§

impl Send for Hash

§

impl !Sync for Hash

§

impl Unpin for Hash

§

impl UnwindSafe for Hash

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.