From db86aa9d5a744790c865115373428a7c4cc7ec3e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 22 Jun 2020 01:25:16 +0200 Subject: [PATCH] xmpp-parsers: Bump RustCrypto crates --- xmpp-parsers/Cargo.toml | 10 +++++----- xmpp-parsers/src/caps.rs | 14 +++++++++----- xmpp-parsers/src/ecaps2.rs | 14 +++++++++----- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/xmpp-parsers/Cargo.toml b/xmpp-parsers/Cargo.toml index 4c28d4d1..e869ace1 100644 --- a/xmpp-parsers/Cargo.toml +++ b/xmpp-parsers/Cargo.toml @@ -17,11 +17,11 @@ edition = "2018" minidom = "0.12.0" jid = { version = "0.9", features = ["minidom"] } base64 = "0.12" -digest = "0.8" -sha-1 = "0.8" -sha2 = "0.8" -sha3 = "0.8" -blake2 = "0.8" +digest = "0.9" +sha-1 = "0.9" +sha2 = "0.9" +sha3 = "0.9" +blake2 = "0.9" chrono = "0.4.5" [features] diff --git a/xmpp-parsers/src/caps.rs b/xmpp-parsers/src/caps.rs index 93dd69f9..2b5e2fb0 100644 --- a/xmpp-parsers/src/caps.rs +++ b/xmpp-parsers/src/caps.rs @@ -12,7 +12,7 @@ use crate::presence::PresencePayload; use crate::util::error::Error; use crate::Element; use blake2::VarBlake2b; -use digest::{Digest, Input, VariableOutput}; +use digest::{Digest, Update, VariableOutput}; use sha1::Sha1; use sha2::{Sha256, Sha512}; use sha3::{Sha3_256, Sha3_512}; @@ -190,13 +190,17 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result { } Algo::Blake2b_256 => { let mut hasher = VarBlake2b::new(32).unwrap(); - hasher.input(data); - hasher.vec_result() + hasher.update(data); + let mut vec = Vec::with_capacity(32); + hasher.finalize_variable(|slice| vec.extend_from_slice(slice)); + vec } Algo::Blake2b_512 => { let mut hasher = VarBlake2b::new(64).unwrap(); - hasher.input(data); - hasher.vec_result() + hasher.update(data); + let mut vec = Vec::with_capacity(64); + hasher.finalize_variable(|slice| vec.extend_from_slice(slice)); + vec } Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), }, diff --git a/xmpp-parsers/src/ecaps2.rs b/xmpp-parsers/src/ecaps2.rs index 0240e187..4ca1f2a2 100644 --- a/xmpp-parsers/src/ecaps2.rs +++ b/xmpp-parsers/src/ecaps2.rs @@ -11,7 +11,7 @@ use crate::ns; use crate::presence::PresencePayload; use crate::util::error::Error; use blake2::VarBlake2b; -use digest::{Digest, Input, VariableOutput}; +use digest::{Digest, Update, VariableOutput}; use sha2::{Sha256, Sha512}; use sha3::{Sha3_256, Sha3_512}; @@ -147,13 +147,17 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result { } Algo::Blake2b_256 => { let mut hasher = VarBlake2b::new(32).unwrap(); - hasher.input(data); - hasher.vec_result() + hasher.update(data); + let mut vec = Vec::with_capacity(32); + hasher.finalize_variable(|slice| vec.extend_from_slice(slice)); + vec } Algo::Blake2b_512 => { let mut hasher = VarBlake2b::new(64).unwrap(); - hasher.input(data); - hasher.vec_result() + hasher.update(data); + let mut vec = Vec::with_capacity(64); + hasher.finalize_variable(|slice| vec.extend_from_slice(slice)); + vec } Algo::Sha_1 => return Err(Error::ParseError("Disabled algorithm sha-1: unsafe.")), Algo::Unknown(_algo) => return Err(Error::ParseError("Unknown algorithm in ecaps2.")),