mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
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 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<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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base64;
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
|
|
Loading…
Reference in a new issue