Skip to content

Commit

Permalink
feat: compute_hash_on_elements takes ExactSizeIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jun 3, 2024
1 parent 1ba71e3 commit c4e700a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions starknet-core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &'a FieldElement>,
II: IntoIterator<IntoIter = ESI>,
{
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(&current_hash, item);
}

let data_len = FieldElement::from(data.len());
pedersen_hash(&current_hash, &data_len)
}

Expand Down

0 comments on commit c4e700a

Please sign in to comment.