hashes: Add two constructors.
This commit is contained in:
parent
d83624c8a4
commit
c762a03c39
1 changed files with 14 additions and 1 deletions
|
@ -13,6 +13,7 @@ use error::Error;
|
||||||
|
|
||||||
use ns;
|
use ns;
|
||||||
use helpers::Base64;
|
use helpers::Base64;
|
||||||
|
use base64;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -76,10 +77,22 @@ generate_element_with_text!(
|
||||||
hash: Base64<Vec<u8>>
|
hash: Base64<Vec<u8>>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
impl Hash {
|
||||||
|
pub fn new(algo: Algo, hash: Vec<u8>) -> Hash {
|
||||||
|
Hash {
|
||||||
|
algo,
|
||||||
|
hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_base64(algo: Algo, hash: &str) -> Result<Hash, Error> {
|
||||||
|
Ok(Hash::new(algo, base64::decode(hash)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use base64;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
|
|
Loading…
Reference in a new issue