Use Rust's TryInto for [u8; 32]

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
This commit is contained in:
Deirdre Connolly 2023-04-24 18:21:37 -04:00 committed by GitHub
parent edffbdd596
commit 282c3b16ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 9 deletions

View File

@ -149,15 +149,7 @@ pub(crate) fn test_non_adjacent_form_for_scalar<Scalar: NonAdjacentForm>(w: usiz
.expect("The reconstructed scalar is negative.")
.to_bytes_le();
// Check that the reconstructed scalar is not too big.
assert!(reconstructed_scalar.len() <= 32);
// Convert the reconstructed scalar to a fixed byte array so we can compare it with the orginal
// scalar.
let mut reconstructed_scalar_bytes: [u8; 32] = [0; 32];
for (i, byte) in reconstructed_scalar.iter().enumerate() {
reconstructed_scalar_bytes[i] = *byte;
}
let reconstructed_scalar_bytes: [u8; 32] = reconstructed_scalar.try_into().unwrap();
// Check that the reconstructed scalar matches the original one.
assert_eq!(reconstructed_scalar_bytes, scalar.inner_to_bytes());