[−][src]Struct openssl::hash::Hasher  
Provides message digest (hash) computation.
Examples
Calculate a hash in one go:
use openssl::hash::{hash, MessageDigest}; let data = b"\x42\xF4\x97\xE0"; let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; let res = hash(MessageDigest::md5(), data).unwrap(); assert_eq!(&*res, spec);
Supply the input in chunks:
use openssl::hash::{Hasher, MessageDigest}; let data = [b"\x42\xF4", b"\x97\xE0"]; let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; let mut h = Hasher::new(MessageDigest::md5()).unwrap(); h.update(data[0]).unwrap(); h.update(data[1]).unwrap(); let res = h.finish().unwrap(); assert_eq!(&*res, spec);
Warning
Don't actually use MD5 and SHA-1 hashes, they're not secure anymore.
Don't ever hash passwords, use the functions in the pkcs5 module or bcrypt/scrypt instead.
Methods
impl Hasher[src] 
impl Hasherpub fn new(ty: MessageDigest) -> Result<Hasher, ErrorStack>[src] 
pub fn new(ty: MessageDigest) -> Result<Hasher, ErrorStack>Creates a new Hasher with the specified hash type.
pub fn update(&mut self, data: &[u8]) -> Result<(), ErrorStack>[src] 
pub fn update(&mut self, data: &[u8]) -> Result<(), ErrorStack>Feeds data into the hasher.
pub fn finish(&mut self) -> Result<DigestBytes, ErrorStack>[src] 
pub fn finish(&mut self) -> Result<DigestBytes, ErrorStack>Returns the hash of the data written and resets the hasher.
Trait Implementations
impl Clone for Hasher[src] 
impl Clone for HasherⓘImportant traits for Hasherfn clone(&self) -> Hasher[src] 
fn clone(&self) -> HasherReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src] 
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Drop for Hasher[src] 
impl Drop for Hasherimpl Sync for Hasher[src] 
impl Sync for Hasherimpl Send for Hasher[src] 
impl Send for Hasherimpl Write for Hasher[src] 
impl Write for Hasherfn write(&mut self, buf: &[u8]) -> Result<usize>[src] 
fn write(&mut self, buf: &[u8]) -> Result<usize>Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>[src] 
fn flush(&mut self) -> Result<()>Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src] 
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src] 
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self1.0.0[src] 
fn by_ref(&mut self) -> &mut SelfCreates a "by reference" adaptor for this instance of Write. Read more
Blanket Implementations
impl<T> From for T[src] 
impl<T> From for Timpl<T, U> Into for T where
    U: From<T>, [src] 
impl<T, U> Into for T where
    U: From<T>, impl<T> ToOwned for T where
    T: Clone, [src] 
impl<T> ToOwned for T where
    T: Clone, type Owned = T
fn to_owned(&self) -> T[src] 
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src] 
fn clone_into(&self, target: &mut T)🔬 This is a nightly-only experimental API.  (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
    T: From<U>, [src] 
impl<T, U> TryFrom for T where
    T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src] 
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
    T: ?Sized, [src] 
impl<T> Borrow for T where
    T: ?Sized, impl<T> BorrowMut for T where
    T: ?Sized, [src] 
impl<T> BorrowMut for T where
    T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src] 
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
    U: TryFrom<T>, [src] 
impl<T, U> TryInto for T where
    U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src] 
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
    T: 'static + ?Sized, [src] 
impl<T> Any for T where
    T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src] 
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API.  (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more