[][src]Struct md6::Md6

pub struct Md6 { /* fields omitted */ }

Hashing state for multiple data sets.

Example

Hashing a string split into multiple chunks.

let mut state = Md6::new(256).unwrap();

state.update(b"Abolish ");
state.update(b"the ");
state.update(b"bourgeoisie");
state.update(b"!");

let mut result = [0; 32];
state.finalise(&mut result);
assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0x49, 0x23, 0xE7, 0xB0, 0x53, 0x32, 0x05, 0xB0,
                0x25, 0xC5, 0xD4, 0xDB, 0x37, 0xB8, 0x99, 0x12,
                0x16, 0x2E, 0xFD, 0xF4, 0xDA, 0xC2, 0x2C, 0xFF,
                0xE6, 0x27, 0xF1, 0x11, 0xEC, 0x05, 0x2F, 0xB5]);

A Write implementation is also provided:

let mut state = Md6::new(256).unwrap();
io::copy(&mut &b"The lazy fox jumps over the lazy dog."[..], &mut state).unwrap();

let mut result = [0; 32];
state.finalise(&mut result);
assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0x06, 0x60, 0xBB, 0x89, 0x85, 0x06, 0xE4, 0xD9,
                0x29, 0x8C, 0xD1, 0xB0, 0x40, 0x73, 0x49, 0x60,
                0x47, 0x3E, 0x25, 0xA4, 0x9D, 0x52, 0x34, 0xBB,
                0x2A, 0xCA, 0x31, 0x57, 0xD1, 0xAF, 0x27, 0xAA]);

Implementations

impl Md6[src]

pub fn new(hashbitlen: i32) -> Result<Md6>[src]

Create a new hash state and initialise it with the given bit length.

hashbitlen is the hash output length. Must be between 1 and 512.

Returns:

  • Err(Md6Error::BadHashbitlen) if hashbitlen is not any of the mentioned above, or
  • Ok(Md6) if initialisation succeeds.

Examples

Incorrect hashbitlen

assert_eq!(Md6::new(0).map(|_| ()), Err(md6::Md6Error::BadHashbitlen));
assert_eq!(Md6::new(1024).map(|_| ()), Err(md6::Md6Error::BadHashbitlen));

Creating a 512-long state

Md6::new(512).unwrap();

pub fn update(&mut self, data: &[u8])[src]

Append the provided data to the hash function.

Examples

Hashing a part of a short story

let mut result = [0; 64];

let mut state = Md6::new(512).unwrap();
state.update("    Serbiańcy znowu się pochlali, ale w sumie".as_bytes());
state.update("czegoż się po wschodnich słowianach spodziewać, swoją".as_bytes());
state.update("drogą. I, jak to wszystkim homo sapiensom się dzieje".as_bytes());
state.update("filozofować poczęli.".as_bytes());
state.finalise(&mut result);

assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0xD4, 0xAC, 0x5B, 0xDA, 0x95, 0x44, 0xCC, 0x3F,
                0xFB, 0x59, 0x4B, 0x62, 0x84, 0xEF, 0x07, 0xDD,
                0x59, 0xE7, 0x94, 0x2D, 0xCA, 0xCA, 0x07, 0x52,
                0x14, 0x13, 0xE8, 0x06, 0xBD, 0x84, 0xB8, 0xC7,
                0x8F, 0xB8, 0x03, 0x24, 0x39, 0xC8, 0x2E, 0xEC,
                0x9F, 0x7F, 0x4F, 0xDA, 0xF8, 0x8A, 0x4B, 0x5F,
                0x9D, 0xF8, 0xFD, 0x47, 0x0C, 0x4F, 0x2F, 0x4B,
                0xCD, 0xDF, 0xAF, 0x13, 0xE1, 0xE1, 0x4D, 0x9D]);

pub fn finalise(&mut self, hashval: &mut [u8])[src]

Finish hashing and store the output result in the provided space.

The provided space must not be smaller than the hash function's size, if the provided space is smaller than the hash function's size, the behaviour is undefined.

Examples

Storing and verifying results of all possible sizes.

let mut result_64  = [0; 8];
let mut result_128 = [0; 16];
let mut result_256 = [0; 32];
let mut result_512 = [0; 64];

let mut state_64  = Md6::new(64) .unwrap();
let mut state_128 = Md6::new(128).unwrap();
let mut state_256 = Md6::new(256).unwrap();
let mut state_512 = Md6::new(512).unwrap();

state_64 .update(b"The lazy fox jumps over the lazy dog.");
state_128.update(b"The lazy fox jumps over the lazy dog.");
state_256.update(b"The lazy fox jumps over the lazy dog.");
state_512.update(b"The lazy fox jumps over the lazy dog.");

state_64 .finalise(&mut result_64);
state_128.finalise(&mut result_128);
state_256.finalise(&mut result_256);
state_512.finalise(&mut result_512);

assert_eq!(Vec::from_iter(result_64.iter().map(|&i| i)),
           vec![0xF3, 0x50, 0x60, 0xAE, 0xD7, 0xF0, 0xB0, 0x96]);
assert_eq!(Vec::from_iter(result_128.iter().map(|&i| i)),
           vec![0x08, 0x5E, 0xA5, 0xF6, 0x6D, 0x2A, 0xC1, 0xF3,
                0xCF, 0xC5, 0x6F, 0xA3, 0x7D, 0x1B, 0xEC, 0x9C]);
assert_eq!(Vec::from_iter(result_256.iter().map(|&i| i)),
           vec![0x06, 0x60, 0xBB, 0x89, 0x85, 0x06, 0xE4, 0xD9,
                0x29, 0x8C, 0xD1, 0xB0, 0x40, 0x73, 0x49, 0x60,
                0x47, 0x3E, 0x25, 0xA4, 0x9D, 0x52, 0x34, 0xBB,
                0x2A, 0xCA, 0x31, 0x57, 0xD1, 0xAF, 0x27, 0xAA]);
assert_eq!(Vec::from_iter(result_512.iter().map(|&i| i)),
           vec![0xA5, 0xFE, 0xC7, 0x36, 0x81, 0xFA, 0x64, 0xBE,
                0xE7, 0x2D, 0xB6, 0x05, 0x35, 0x26, 0x6C, 0x00,
                0x6B, 0x2A, 0x49, 0x54, 0x04, 0x7E, 0x39, 0x05,
                0xD1, 0xFE, 0xB3, 0x25, 0x21, 0x01, 0x81, 0x2D,
                0xF2, 0x20, 0xC9, 0x09, 0xD4, 0xD7, 0xB7, 0x94,
                0x53, 0xB4, 0x2D, 0xAD, 0x6D, 0x75, 0x52, 0xC7,
                0x82, 0xE8, 0x4E, 0xFC, 0x3C, 0x34, 0x5B, 0x0C,
                0xFF, 0x72, 0x1B, 0x56, 0x73, 0x05, 0x6B, 0x75]);

Trait Implementations

impl Drop for Md6[src]

impl Write for Md6[src]

The Write implementation updates the state with the provided data.

For example, to hash a file:

let mut state = Md6::new(256).unwrap();
io::copy(&mut File::open("LICENSE").unwrap(), &mut state).unwrap();

let mut result = [0; 32];
state.finalise(&mut result);
assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0xB7, 0x82, 0xA1, 0xEA, 0xDE, 0xC5, 0x46, 0x3E,
                0x1D, 0xCF, 0x56, 0xA2, 0xD7, 0x52, 0x23, 0x82,
                0xA3, 0x02, 0xE6, 0xB6, 0x1D, 0x45, 0xA8, 0xBF,
                0x95, 0x12, 0x92, 0x1E, 0xAD, 0x21, 0x3E, 0x47]);

Auto Trait Implementations

impl RefUnwindSafe for Md6

impl !Send for Md6

impl !Sync for Md6

impl Unpin for Md6

impl UnwindSafe for Md6

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