diff --git a/src/hashes.rs b/src/hashes.rs index 535f99c5..e414b91a 100644 --- a/src/hashes.rs +++ b/src/hashes.rs @@ -13,6 +13,7 @@ use error::Error; use ns; use helpers::Base64; +use base64; #[allow(non_camel_case_types)] #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -76,10 +77,22 @@ generate_element_with_text!( hash: Base64> ); +impl Hash { + pub fn new(algo: Algo, hash: Vec) -> Hash { + Hash { + algo, + hash, + } + } + + pub fn from_base64(algo: Algo, hash: &str) -> Result { + Ok(Hash::new(algo, base64::decode(hash)?)) + } +} + #[cfg(test)] mod tests { use super::*; - use base64; #[test] fn test_simple() {