Struct openssl::crypto::hash::Hasher
[−]
[src]
pub struct Hasher { // some fields omitted }
Provides message digest (hash) computation.
Examples
Calculate a hash in one go.
use openssl::crypto::hash::{hash, Type}; 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(Type::MD5, data); assert_eq!(res, spec);
Use the Write
trait to supply the input in chunks.
use std::io::prelude::*; use openssl::crypto::hash::{Hasher, Type}; 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(Type::MD5); h.write_all(data[0]); h.write_all(data[1]); let res = h.finish(); 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 crypto::pkcs5
or bcrypt/scrypt instead.
Methods
impl Hasher
[src]
fn new(ty: Type) -> Hasher
Creates a new Hasher
with the specified hash type.
fn finish(&mut self) -> Vec<u8>
Returns the hash of the data written since creation or
the last finish
and resets the hasher.
Trait Implementations
impl Write for Hasher
[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<()>
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
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more
impl Clone for Hasher
[src]
fn clone(&self) -> Hasher
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more