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 Writer trait to supply the input in chunks.

use std::old_io::Writer;
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

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 Writer for Hasher

fn write_all(&mut self, buf: &[u8]) -> Result<(), IoError>

fn write(&mut self, buf: &[u8]) -> Result<(), IoError>

fn flush(&mut self) -> Result<(), IoError>

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), IoError>

fn write_str(&mut self, s: &str) -> Result<(), IoError>

fn write_line(&mut self, s: &str) -> Result<(), IoError>

fn write_char(&mut self, c: char) -> Result<(), IoError>

fn write_int(&mut self, n: isize) -> Result<(), IoError>

fn write_uint(&mut self, n: usize) -> Result<(), IoError>

fn write_le_uint(&mut self, n: usize) -> Result<(), IoError>

fn write_le_int(&mut self, n: isize) -> Result<(), IoError>

fn write_be_uint(&mut self, n: usize) -> Result<(), IoError>

fn write_be_int(&mut self, n: isize) -> Result<(), IoError>

fn write_be_u64(&mut self, n: u64) -> Result<(), IoError>

fn write_be_u32(&mut self, n: u32) -> Result<(), IoError>

fn write_be_u16(&mut self, n: u16) -> Result<(), IoError>

fn write_be_i64(&mut self, n: i64) -> Result<(), IoError>

fn write_be_i32(&mut self, n: i32) -> Result<(), IoError>

fn write_be_i16(&mut self, n: i16) -> Result<(), IoError>

fn write_be_f64(&mut self, f: f64) -> Result<(), IoError>

fn write_be_f32(&mut self, f: f32) -> Result<(), IoError>

fn write_le_u64(&mut self, n: u64) -> Result<(), IoError>

fn write_le_u32(&mut self, n: u32) -> Result<(), IoError>

fn write_le_u16(&mut self, n: u16) -> Result<(), IoError>

fn write_le_i64(&mut self, n: i64) -> Result<(), IoError>

fn write_le_i32(&mut self, n: i32) -> Result<(), IoError>

fn write_le_i16(&mut self, n: i16) -> Result<(), IoError>

fn write_le_f64(&mut self, f: f64) -> Result<(), IoError>

fn write_le_f32(&mut self, f: f32) -> Result<(), IoError>

fn write_u8(&mut self, n: u8) -> Result<(), IoError>

fn write_i8(&mut self, n: i8) -> Result<(), IoError>

impl Clone for Hasher

fn clone(&self) -> Hasher

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

impl Drop for Hasher

fn drop(&mut self)