From c4e700aa1885c13116eac860afe6e09db9c7af7b 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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/starknet-core/src/crypto.rs b/starknet-core/src/crypto.rs index e703fc24..41af08e8 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: &[FieldElement]) -> FieldElement { +pub fn compute_hash_on_elements<'a, ESI, II>(data: II) -> FieldElement +where + ESI: ExactSizeIterator, + II: IntoIterator, +{ let mut current_hash = FieldElement::ZERO; + let iter = data.into_iter(); + let data_len = FieldElement::from(iter.len()); - for item in data.iter() { + for item in iter { current_hash = pedersen_hash(¤t_hash, item); } - let data_len = FieldElement::from(data.len()); pedersen_hash(¤t_hash, &data_len) }