Skip to content

Commit

Permalink
Other From impl
Browse files Browse the repository at this point in the history
  • Loading branch information
JackPiri committed Jun 7, 2024
1 parent a07ead2 commit a07910a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ impl From<[u32; risc0_zkp::core::digest::DIGEST_WORDS]> for Vk {
Self(value.into())
}
}

impl From<[u8; risc0_zkp::core::digest::DIGEST_BYTES]> for Vk {
fn from(value: [u8; risc0_zkp::core::digest::DIGEST_BYTES]) -> Self {
// Initialize with zeros
let mut value_u32: [u32; risc0_zkp::core::digest::DIGEST_WORDS] =
[0; risc0_zkp::core::digest::DIGEST_WORDS];
// Iterate over chunks of 4 bytes and convert them to u32
for (i, chunk) in value.chunks_exact(4).enumerate() {
let mut single_value: u32 = 0;
for (j, &byte) in chunk.iter().enumerate() {
single_value |= (byte as u32) << (8 * j);
}
value_u32[i] = single_value;
}
Self(value_u32.into())
}
}

0 comments on commit a07910a

Please sign in to comment.