recrypt 0.1.0

A pure-Rust implementation of Transform Encryption, a Proxy Re-encryption scheme
Documentation
use internal::hashable::Hashable;
use sha2;
use sha2::Digest;

pub trait Sha256Hashing {
    fn hash<T: Hashable>(&self, t: &T) -> [u8; 32];
}

pub struct Sha256;

impl Sha256Hashing for Sha256 {
    fn hash<T: Hashable>(&self, t: &T) -> [u8; 32] {
        let mut hasher = sha2::Sha256::default();
        hasher.input(t.to_bytes().as_slice());
        let hash_result = hasher.result();
        //This is currently the best way I know of to do this... Sorry.
        let mut result: [u8; 32] = [0; 32];
        result.clone_from_slice(hash_result.as_slice());
        result
    }
}

#[cfg(test)]
mod test {
    use hex;
    use internal::sha256::*;
    //Test that ensures a manually computed value is correct.
    #[test]
    fn sha256_match_known_value() {
        assert_eq!(
            Sha256.hash(&1u8).to_vec(),
            hex::decode("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a")
                .unwrap()
        );
    }
}