Struct botan::HashFunction
source · pub struct HashFunction { /* private fields */ }Expand description
A hash function object
Implementations§
source§impl HashFunction
impl HashFunction
sourcepub fn new(name: &str) -> Result<HashFunction>
pub fn new(name: &str) -> Result<HashFunction>
sourcepub fn algo_name(&self) -> Result<String>
pub fn algo_name(&self) -> Result<String>
Return the name of this algorithm which may or may not exactly match what was provided to new()
Examples
let hash = botan::HashFunction::new("SHA-384").unwrap();
assert_eq!(hash.algo_name().unwrap(), "SHA-384");sourcepub fn output_length(&self) -> Result<usize>
pub fn output_length(&self) -> Result<usize>
Return the output length of the hash function, in bytes
Examples
let hash = botan::HashFunction::new("SHA-256").unwrap();
assert_eq!(hash.output_length().unwrap(), 32);sourcepub fn block_size(&self) -> Result<usize>
pub fn block_size(&self) -> Result<usize>
Return the block length of the hash function, in bytes
Examples
let hash = botan::HashFunction::new("SHA-256").unwrap();
assert_eq!(hash.block_size().unwrap(), 64);sourcepub fn update(&mut self, data: &[u8]) -> Result<()>
pub fn update(&mut self, data: &[u8]) -> Result<()>
Add data to a hash computation, may be called many times
Examples
let mut hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]).unwrap();
hash.update(&[4,5,6]).unwrap();sourcepub fn finish(&mut self) -> Result<Vec<u8>>
pub fn finish(&mut self) -> Result<Vec<u8>>
Finalize the computation, returning the hash of the message
Examples
let mut hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]).unwrap();
hash.update(&[4,5,6]).unwrap();
let digest = hash.finish().unwrap();sourcepub fn clear(&mut self) -> Result<()>
pub fn clear(&mut self) -> Result<()>
Clear the internal state of the hash function. It acts as if it was newly created, and is ready to compute a new digest. Basically the same as calling final, but without returning a result.
sourcepub fn duplicate(&self) -> Result<HashFunction>
pub fn duplicate(&self) -> Result<HashFunction>
Copy hash object state to a new object, allowing prefixes of messages to be hashed. This function is also called by clone.
Errors
Should not fail but might due to unexpected error
Examples
let mut hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]);
let mut hash2 = hash.duplicate().unwrap();
hash2.update(&[4,5,6]);
let result1 = hash.finish().unwrap(); // hash of 1,2,3
let result2 = hash2.finish().unwrap(); // hash of 1,2,3,4,5,6Trait Implementations§
source§impl Clone for HashFunction
impl Clone for HashFunction
source§fn clone(&self) -> HashFunction
fn clone(&self) -> HashFunction
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more