Crate digest_hash[][src]

Utilities for stable cryptographic hashing of data structures.

Example

extern crate digest_hash;
extern crate sha2;

use digest_hash::{BigEndian, Hash};
use digest_hash::EndianInput;
use sha2::{Sha256, Digest};

pub struct MyHashStableStruct {
    foo: u32,
    bar: i16
}

impl Hash for MyHashStableStruct {
    fn hash<H: EndianInput>(&self, digest: &mut H) {
        self.foo.hash(digest);
        self.bar.hash(digest);
    }
}

fn main() {
    let inst = MyHashStableStruct { foo: 0x01020304, bar: 0x0506 };

    let mut hasher = BigEndian::<Sha256>::new();
    inst.hash(&mut hasher);
    let hash = hasher.result();

    const EXPECTED: &[u8] =
            &[0x71, 0x92, 0x38, 0x5c, 0x3c, 0x06, 0x05, 0xde,
              0x55, 0xbb, 0x94, 0x76, 0xce, 0x1d, 0x90, 0x74,
              0x81, 0x90, 0xec, 0xb3, 0x2a, 0x8e, 0xed, 0x7f,
              0x52, 0x07, 0xb3, 0x0c, 0xf6, 0xa1, 0xfe, 0x89];
    assert_eq!(hash.as_ref(), EXPECTED);
}

Re-exports

pub extern crate byteorder;
pub extern crate digest;

Modules

personality

Helper functions for hashing data in a specific representation.

Structs

Endian

An adapter to provide digest functions with endian-awareness.

Traits

EndianInput

Extends digest::Input to provide primitives for type-safe hashing.

Hash

A cryptographically hashable type.

Type Definitions

BigEndian

A type alias for Endian specialized for big endian byte order.

LittleEndian

A type alias for Endian specialized for little endian byte order.

NetworkEndian

A type alias for Endian specialized for network byte order.