[][src]Struct win_crypto_ng::hash::Hash

pub struct Hash { /* fields omitted */ }

Hashing operation

Implementations

impl Hash[src]

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

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();

pub fn finish(self) -> Result<Buffer>[src]

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,
]);

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

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);

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

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

impl Clone for Hash[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.