Struct win_crypto_ng::hash::Hash
source · pub struct Hash { /* private fields */ }
Expand description
Hashing operation
Implementations§
source§impl Hash
impl Hash
sourcepub fn hash(&mut self, data: &[u8]) -> Result<()>
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();
sourcepub fn finish(self) -> Result<Buffer>
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,
]);
sourcepub fn hash_size(&self) -> Result<usize>
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);
sourcepub fn hash_algorithm(&self) -> Result<HashAlgorithmId>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more