From c23eef88df20f9f946acd4d90a61f197d0989be2 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Sun, 17 Mar 2024 20:26:49 -0700 Subject: [PATCH] fsb: reverse order of serialization for consistency --- fsb/src/macros.rs | 8 ++-- fsb/tests/mod.rs | 102 +++++++++++++++++++++++----------------------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/fsb/src/macros.rs b/fsb/src/macros.rs index 5b4a189c..59845f79 100644 --- a/fsb/src/macros.rs +++ b/fsb/src/macros.rs @@ -101,8 +101,9 @@ macro_rules! fsb_impl { fn serialize(&self) -> SerializedState { let mut serialized_state = SerializedState::::default(); - serialized_state[..8].copy_from_slice(&self.blocks_len.to_le_bytes()); - serialized_state[8..].copy_from_slice(&self.state[..]); + serialized_state[..self.state.len()].copy_from_slice(&self.state[..]); + serialized_state[self.state.len()..] + .copy_from_slice(&self.blocks_len.to_le_bytes()); serialized_state } @@ -110,7 +111,8 @@ macro_rules! fsb_impl { fn deserialize( serialized_state: &SerializedState, ) -> Result { - let (serialized_block_len, serialized_state) = serialized_state.split::(); + let (serialized_state, serialized_block_len) = + serialized_state.split::<$statesize>(); let mut state = [0; $r / 8]; state.copy_from_slice(serialized_state.as_ref()); diff --git a/fsb/tests/mod.rs b/fsb/tests/mod.rs index e2d9b780..4a967c85 100644 --- a/fsb/tests/mod.rs +++ b/fsb/tests/mod.rs @@ -16,12 +16,12 @@ hash_serialization_test!( fsb160_serialization, Fsb160, hex!(" - 0100000000000000e269a086505e9493 - fa92ed509f6cdce851dd58654160a8c8 - a499a953a479c169d46c0576d8e7b262 - 341087f58eb3dc9d3002451f8f0d484c - bdc8b342afef13e54f2fce12e400eca0 - a6bc0b8837f999c30113000000000000 + e269a086505e9493fa92ed509f6cdce8 + 51dd58654160a8c8a499a953a479c169 + d46c0576d8e7b262341087f58eb3dc9d + 3002451f8f0d484cbdc8b342afef13e5 + 4f2fce12e400eca0a6bc0b8837f999c3 + 01000000000000000113000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 @@ -33,14 +33,14 @@ hash_serialization_test!( fsb224_serialization, Fsb224, hex!(" - 0100000000000000bfba3bbd79050b44 - 28d239ec4eb25277b228898bd26c04cc - f11e052944e72b61aae3f1a0a6cdb862 - d87fac21fefb1dc14074cfc45d899408 - 7dc70d1d5308b6b1f68f6eea5d886904 - dfcab198e62f6c9767ae365fc648b1bb - 7d00f65ff276373a7a1b4d80efdd7af5 - fce3b0e93371172a0113000000000000 + bfba3bbd79050b4428d239ec4eb25277 + b228898bd26c04ccf11e052944e72b61 + aae3f1a0a6cdb862d87fac21fefb1dc1 + 4074cfc45d8994087dc70d1d5308b6b1 + f68f6eea5d886904dfcab198e62f6c97 + 67ae365fc648b1bb7d00f65ff276373a + 7a1b4d80efdd7af5fce3b0e93371172a + 01000000000000000113000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 @@ -54,15 +54,15 @@ hash_serialization_test!( fsb256_serialization, Fsb256, hex!(" - 01000000000000006c4fef5401baa182 - 5e74fe2a150dd74655ba10d8fa2db4ee - 3e6925de2cf4a83a5121e2ded528f926 - 13ec858045c1bdd15a11ce8bd4df1a3f - 409dfc9d1025d333360f30a342f41701 - 8fcf0ff1c5dddb042a18453d707d2772 - 1e57fd182d93294589a1c3ef007e6bb3 - b59f2a361094e21d6c72d213545a6612 - a2adc547968a03e90113000000000000 + 6c4fef5401baa1825e74fe2a150dd746 + 55ba10d8fa2db4ee3e6925de2cf4a83a + 5121e2ded528f92613ec858045c1bdd1 + 5a11ce8bd4df1a3f409dfc9d1025d333 + 360f30a342f417018fcf0ff1c5dddb04 + 2a18453d707d27721e57fd182d932945 + 89a1c3ef007e6bb3b59f2a361094e21d + 6c72d213545a6612a2adc547968a03e9 + 01000000000000000113000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 @@ -77,18 +77,18 @@ hash_serialization_test!( fsb384_serialization, Fsb384, hex!(" - 010000000000000041825b73ae6b5cdc - 91b8b70723dc1f9297fec62f09c17c75 - a2326e3d7664efb5df1104db5c711016 - d161187f3174ef77f5e0545c917d0137 - 5537d15cf90c838d2f5fd5a294c7012d - 80a0f6a6240f90f9a6976812ec60fdd3 - 5bbc1a064287308e1d916cb4d59c02b1 - 9ab2d20e1b9b2acbe826c4d0022db322 - e3314fe0cf232cdd75b61c653bf30569 - ca76dd11bd032d03bc83a0e59964eb5d - d77a22d0a459de63ab5ff6ce1207a9da - ed690c36399f730643a1628e0f33650a + 41825b73ae6b5cdc91b8b70723dc1f92 + 97fec62f09c17c75a2326e3d7664efb5 + df1104db5c711016d161187f3174ef77 + f5e0545c917d01375537d15cf90c838d + 2f5fd5a294c7012d80a0f6a6240f90f9 + a6976812ec60fdd35bbc1a064287308e + 1d916cb4d59c02b19ab2d20e1b9b2acb + e826c4d0022db322e3314fe0cf232cdd + 75b61c653bf30569ca76dd11bd032d03 + bc83a0e59964eb5dd77a22d0a459de63 + ab5ff6ce1207a9daed690c36399f7306 + 43a1628e0f33650a0100000000000000 01130000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 @@ -105,22 +105,22 @@ hash_serialization_test!( fsb512_serialization, Fsb512, hex!(" - 01000000000000004feff733b532b076 - 7d0bbe8804f60ebcbbf33aa6796e608d - 37e6e24dcf21663631312286c6efa794 - b237f05df2838526cb5120291a53566b - b784ff32d2ea5464693cd68fc52a3737 - 5160c0a4f4b8dae806703a98720180c4 - abaa2c195a6ede59ed68fc5caae61720 - 03ad9195d7ae774710d7a0c46772a721 - 6e553a39dbeac282fa2848e7038eec7c - 78f7da35db4cf8ead35f2f140ec49203 - f1d3afe24fe4100a9d0cc5fdb1e964ed - 48fe786e2bfdabe470c148f65c67c21c - c6794b8e1eb90e6a39800334a2016e20 - 81f5a458fcd348d8778dc4090066f390 - 6b835a1283c975694e1dc38fef18dd35 - d2d4f283d0bc1502db72a91871a23bc4 + 4feff733b532b0767d0bbe8804f60ebc + bbf33aa6796e608d37e6e24dcf216636 + 31312286c6efa794b237f05df2838526 + cb5120291a53566bb784ff32d2ea5464 + 693cd68fc52a37375160c0a4f4b8dae8 + 06703a98720180c4abaa2c195a6ede59 + ed68fc5caae6172003ad9195d7ae7747 + 10d7a0c46772a7216e553a39dbeac282 + fa2848e7038eec7c78f7da35db4cf8ea + d35f2f140ec49203f1d3afe24fe4100a + 9d0cc5fdb1e964ed48fe786e2bfdabe4 + 70c148f65c67c21cc6794b8e1eb90e6a + 39800334a2016e2081f5a458fcd348d8 + 778dc4090066f3906b835a1283c97569 + 4e1dc38fef18dd35d2d4f283d0bc1502 + db72a91871a23bc40100000000000000 01130000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000