Struct HashFunction

Source
pub struct HashFunction { /* private fields */ }
Expand description

A hash function object

Implementations§

Source§

impl HashFunction

Source

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

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

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

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

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

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

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

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.

Source

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,6

Trait Implementations§

Source§

impl Clone for HashFunction

Source§

fn clone(&self) -> HashFunction

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HashFunction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for HashFunction

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for HashFunction

Source§

impl Sync for HashFunction

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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

Source§

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.