Skip to content

Commit

Permalink
remove unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Oct 10, 2023
1 parent 5b06748 commit 0995c51
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/whisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,10 @@ pub fn rand_scalar<T: RngCore>(rng: &mut T) -> Fr {
}

/// Serialize field element to bytes
pub fn to_bytes_fr(fr: &Fr) -> FieldElementBytes {
let mut bytes = [0u8; FIELD_ELEMENT_SIZE];

fr.serialize_uncompressed(&mut bytes[..]).unwrap();

bytes
pub fn to_bytes_fr(fr: &Fr) -> Result<FieldElementBytes, SerializationError> {
let mut out = [0u8; FIELD_ELEMENT_SIZE];
fr.serialize_uncompressed(&mut out[..])?;
Ok(out)
}

/// Convert bytes to a BLS field scalar. The output is not uniform over the BLS field.
Expand All @@ -339,7 +337,7 @@ mod tests {
hex::decode("9ebde6d84a58debe5ef02c729366a76078a15a653aa6234aeab6996ce47f8d2a")
.unwrap();
let k = from_bytes_fr(&k_bytes);
assert_eq!(to_bytes_fr(&k).as_slice(), &k_bytes);
assert_eq!(to_bytes_fr(&k).unwrap().as_slice(), &k_bytes);
}

#[test]
Expand Down

0 comments on commit 0995c51

Please sign in to comment.