aboutsummaryrefslogtreecommitdiff
path: root/src/test.rs
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2024-07-14 19:27:37 -0700
committerJack O'Connor <[email protected]>2024-07-14 19:44:45 -0700
commit43ce639d136a41289595749710212ef4f67f5f7f (patch)
treef6ca2ccce931665d520d68fda3fe96dc4e0e8fc2 /src/test.rs
parentfc2f7e4206f016b0cac0593f23a7d5976ce066e6 (diff)
Revert "serialize Hash with serde_bytes"
This mostly reverts commits 8416b1658c2690dc6351bdc7e0975b0d5f1a5282 and dd0afd640ad97b5ebcf887107162009a23ffdca0. Changing the serialization of Hash can only be backwards-compatible in self-describing formats like CBOR. In non-self-describing formats like bincode, the deserializer has to know in advance which serialization format was used. Fixes https://github.com/BLAKE3-team/BLAKE3/issues/414. Reopens https://github.com/BLAKE3-team/BLAKE3/issues/412.
Diffstat (limited to 'src/test.rs')
-rw-r--r--src/test.rs29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/test.rs b/src/test.rs
index 9f73417..b716e1b 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -826,25 +826,28 @@ fn test_serde() {
assert_eq!(
cbor,
[
- 0x58, 0x20, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
- 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
- 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
+ 0x98, 0x20, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
+ 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
+ 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
+ 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
+ 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
]
);
let hash_from_cbor: crate::Hash = ciborium::from_reader(&cbor[..]).unwrap();
assert_eq!(hash_from_cbor, hash);
- // Before we used serde_bytes, the hash [254; 32] would serialize as an array instead of a
- // byte string, like this. Make sure we can still deserialize this representation.
- let old_cbor: &[u8] = &[
- 0x98, 0x20, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18,
- 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
- 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18,
- 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
- 0x18, 0xfe, 0x18, 0xfe, 0x18, 0xfe,
+ // Version 1.5.2 of this crate changed the default serialization format to a bytestring
+ // (instead of an array/list) to save bytes on the wire. That was a backwards compatibility
+ // mistake for non-self-describing formats, and it's been reverted. Since some small number of
+ // serialized bytestrings will probably exist forever in the wild, we shold test that we can
+ // still deserialize these from self-describing formats.
+ let bytestring_cbor: &[u8] = &[
+ 0x58, 0x20, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
+ 0xfe, 0xfe, 0xfe, 0xfe,
];
- let hash_from_old_cbor: crate::Hash = ciborium::from_reader(old_cbor).unwrap();
- assert_eq!(hash_from_old_cbor, hash);
+ let hash_from_bytestring_cbor: crate::Hash = ciborium::from_reader(bytestring_cbor).unwrap();
+ assert_eq!(hash_from_bytestring_cbor, hash);
}
// `cargo +nightly miri test` currently works, but it takes forever, because some of our test