From c762a03c39875f481db04e2bacbba6f3a398f793 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 4 May 2018 19:10:04 +0200 Subject: [PATCH] hashes: Add two constructors. --- src/hashes.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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() {