mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
caps: Do the same fixes, unbreak blake2 and simplify code.
This commit is contained in:
parent
702c4d2932
commit
9c9ffe70a7
1 changed files with 7 additions and 22 deletions
29
src/caps.rs
29
src/caps.rs
|
@ -15,12 +15,11 @@ use error::Error;
|
|||
use ns;
|
||||
use base64;
|
||||
|
||||
use digest::Digest;
|
||||
use sha1::Sha1;
|
||||
use sha2::{Sha256, Sha512};
|
||||
use sha3::{Sha3_256, Sha3_512};
|
||||
//use blake2::Blake2b;
|
||||
//use digest::{Digest, VariableOutput};
|
||||
use blake2::Blake2b;
|
||||
use digest::{Digest, VariableOutput};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Caps {
|
||||
|
@ -141,38 +140,25 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result<Hash, String> {
|
|||
Ok(Hash {
|
||||
hash: match algo {
|
||||
Algo::Sha_1 => {
|
||||
let mut hasher = Sha1::default();
|
||||
hasher.input(data);
|
||||
let hash = hasher.result();
|
||||
let hash = Sha1::digest(data);
|
||||
get_hash_vec(hash.as_slice())
|
||||
},
|
||||
Algo::Sha_256 => {
|
||||
let mut hasher = Sha256::default();
|
||||
hasher.input(data);
|
||||
let hash = hasher.result();
|
||||
let hash = Sha256::digest(data);
|
||||
get_hash_vec(hash.as_slice())
|
||||
},
|
||||
Algo::Sha_512 => {
|
||||
let mut hasher = Sha512::default();
|
||||
hasher.input(data);
|
||||
let hash = hasher.result();
|
||||
let hash = Sha512::digest(data);
|
||||
get_hash_vec(hash.as_slice())
|
||||
},
|
||||
Algo::Sha3_256 => {
|
||||
let mut hasher = Sha3_256::default();
|
||||
hasher.input(data);
|
||||
let hash = hasher.result();
|
||||
let hash = Sha3_256::digest(data);
|
||||
get_hash_vec(hash.as_slice())
|
||||
},
|
||||
Algo::Sha3_512 => {
|
||||
let mut hasher = Sha3_512::default();
|
||||
hasher.input(data);
|
||||
let hash = hasher.result();
|
||||
let hash = Sha3_512::digest(data);
|
||||
get_hash_vec(hash.as_slice())
|
||||
},
|
||||
Algo::Blake2b_256
|
||||
| Algo::Blake2b_512 => panic!("See https://github.com/RustCrypto/hashes/issues/34"),
|
||||
/*
|
||||
Algo::Blake2b_256 => {
|
||||
let mut hasher = Blake2b::default();
|
||||
hasher.input(data);
|
||||
|
@ -187,7 +173,6 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result<Hash, String> {
|
|||
let hash = hasher.variable_result(&mut buf).unwrap();
|
||||
get_hash_vec(hash)
|
||||
},
|
||||
*/
|
||||
Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)),
|
||||
},
|
||||
algo: algo,
|
||||
|
|
Loading…
Reference in a new issue