Don't duplicate logic

This commit is contained in:
David Palm 2018-08-22 14:06:56 +02:00
parent f94c73537f
commit 78d17b4f80
2 changed files with 14 additions and 5 deletions

View File

@ -816,10 +816,7 @@ macro_rules! construct_uint {
impl From<[u8; $n_words * 8]> for $name {
fn from(bytes: [u8; $n_words * 8]) -> Self {
let mut bytes = bytes;
bytes[..].reverse();
let bytes : [u64; $n_words] = unsafe { ::core::mem::transmute(bytes)};
$name(bytes)
bytes[..].as_ref().into()
}
}

View File

@ -1027,6 +1027,19 @@ fn test_u256_from_fixed_array() {
assert_eq!( a_ref, &(U256::from(std::u64::MAX) + 1 + 123));
}
#[test]
fn test_from_ref_to_fixed_array() {
let ary : &[u8; 32] = &[
1,0,1,2,1,0,1,2,
3,0,3,4,3,0,3,4,
5,0,5,6,5,0,5,6,
7,0,7,8,7,0,7,8
];
let big : U256 = ary.into();
// the numbers are each row of 8 bytes reversed and cast to u64
assert_eq!(big, U256([504410889324070664, 360293493601469702, 216176097878868740, 72058702156267778u64]));
}
#[test]
fn test_u512_from_fixed_array() {
let ary = [
@ -1044,7 +1057,6 @@ fn test_u512_from_fixed_array() {
let a_ref : &U512 = &ary.into();
assert_eq!( a_ref, &U512::from(123) );
}
#[test]