From ef5484eff9ffea09720c678c54b49ff5b962e9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= Date: Mon, 3 Jun 2024 12:20:41 +0200 Subject: [PATCH] feat: compute_hash_on_elements takes ExactSizeIterator --- starknet-core/src/crypto.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/starknet-core/src/crypto.rs b/starknet-core/src/crypto.rs index 634faab9..1977f4da 100644 --- a/starknet-core/src/crypto.rs +++ b/starknet-core/src/crypto.rs @@ -46,14 +46,19 @@ mod errors { } pub use errors::{EcdsaSignError, EcdsaVerifyError}; -pub fn compute_hash_on_elements(data: &[Felt]) -> Felt { +pub fn compute_hash_on_elements<'a, ESI, II>(data: II) -> Felt +where + ESI: ExactSizeIterator, + II: IntoIterator, +{ let mut current_hash = Felt::ZERO; + let data_iter = data.into_iter(); + let data_len = Felt::from(data_iter.len()); - for item in data.iter() { - current_hash = pedersen_hash(¤t_hash, item); + for elem in data_iter { + current_hash = pedersen_hash(¤t_hash, elem); } - let data_len = Felt::from(data.len()); pedersen_hash(¤t_hash, &data_len) }