aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2024-07-10 10:00:17 -0700
committerJack O'Connor <[email protected]>2024-07-10 10:00:19 -0700
commit8416b1658c2690dc6351bdc7e0975b0d5f1a5282 (patch)
tree167839fceb0d1545b4b844c464475f1ffbafe261 /src
parent15e21c924f5a0deb27be0a74e881f830d5018706 (diff)
update CBOR tests per @BurningEnlightenment's suggestions
https://github.com/BLAKE3-team/BLAKE3/issues/412#issuecomment-2220970998
Diffstat (limited to 'src')
-rw-r--r--src/test.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/test.rs b/src/test.rs
index b5bd4dc..9f73417 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -809,12 +809,14 @@ fn test_mmap_rayon() -> Result<(), std::io::Error> {
#[cfg(feature = "std")]
#[cfg(feature = "serde")]
fn test_serde() {
- let hash: crate::Hash = [255; 32].into();
+ // Henrik suggested that we use 0xfe / 254 for byte test data instead of 0xff / 255, due to the
+ // fact that 0xfe is not a well formed CBOR item.
+ let hash: crate::Hash = [0xfe; 32].into();
let json = serde_json::to_string(&hash).unwrap();
assert_eq!(
json,
- "[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]",
+ "[254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254]",
);
let hash2: crate::Hash = serde_json::from_str(&json).unwrap();
assert_eq!(hash, hash2);
@@ -824,20 +826,22 @@ fn test_serde() {
assert_eq!(
cbor,
[
- 88, 32, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
+ 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_cbor: crate::Hash = ciborium::from_reader(&cbor[..]).unwrap();
assert_eq!(hash_from_cbor, hash);
- // Before we used serde_bytes, the hash [255; 32] would serialize as an array instead of a
+ // 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] = &[
- 152, 32, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255,
- 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255,
- 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255, 24, 255,
- 24, 255, 24, 255, 24, 255,
+ 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_old_cbor: crate::Hash = ciborium::from_reader(old_cbor).unwrap();
assert_eq!(hash_from_old_cbor, hash);