diff --git a/src/whisk.rs b/src/whisk.rs index aef05c5..eed1b04 100644 --- a/src/whisk.rs +++ b/src/whisk.rs @@ -308,12 +308,10 @@ pub fn rand_scalar(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 { + 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. @@ -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]