mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
Take iterator in calculate_hash()
Avoids unnecessary allocations.
This commit is contained in:
parent
cce83beedb
commit
f1642c92d1
5 changed files with 24 additions and 33 deletions
15
src/utils.rs
15
src/utils.rs
|
|
@ -106,9 +106,18 @@ where
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(keys))]
|
||||
pub(crate) fn calculate_hash(keys: &[&[u8]]) -> Vec<u8> {
|
||||
// We only hash the pdu's event ids, not the whole pdu
|
||||
let bytes = keys.join(&0xFF);
|
||||
pub(crate) fn calculate_hash<'a, I, T>(keys: I) -> Vec<u8>
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: AsRef<[u8]>,
|
||||
{
|
||||
let mut bytes = Vec::new();
|
||||
for (i, key) in keys.into_iter().enumerate() {
|
||||
if i != 0 {
|
||||
bytes.push(0xFF);
|
||||
}
|
||||
bytes.extend_from_slice(key.as_ref());
|
||||
}
|
||||
let hash = digest::digest(&digest::SHA256, &bytes);
|
||||
hash.as_ref().to_owned()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue