Struct botan::HashFunction[][src]

pub struct HashFunction { /* fields omitted */ }

A hash function object

Implementations

impl HashFunction[src]

pub fn new(name: &str) -> Result<HashFunction>[src]

Create a new hash function

Errors

Will fail if the named hash is not known

Examples

assert!(botan::HashFunction::new("SHA-256").is_ok());
assert!(botan::HashFunction::new("Hash9000").is_err());

pub fn algo_name(&self) -> Result<String>[src]

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

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

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

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

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

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

Add data to a hash computation, may be called many times

Examples

let hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]).unwrap();
hash.update(&[4,5,6]).unwrap();

pub fn finish(&self) -> Result<Vec<u8>>[src]

Finalize the computation, returning the hash of the message

Examples

let hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]).unwrap();
hash.update(&[4,5,6]).unwrap();
let digest = hash.finish().unwrap();

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

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.

pub fn duplicate(&self) -> Result<HashFunction>[src]

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 hash = botan::HashFunction::new("SHA-256").unwrap();
hash.update(&[1,2,3]);
let 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,6

Trait Implementations

impl Clone for HashFunction[src]

impl Debug for HashFunction[src]

impl Drop for HashFunction[src]

Auto Trait Implementations

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.