Skip to content

Commit f879b51

Browse files
committed
Ensure StorableBuilder backwards compatibility with v0.3.1
We add a simple test that ensures we can still decode v0.3.1-encoded `Storable`s. Co-authored by Claude AI.
1 parent 5067abc commit f879b51

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/util/storable_builder.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,38 @@ mod tests {
156156
assert_eq!(actual_version, expected_version_a);
157157
assert!(storable_builder.deconstruct(storable_b, &data_key, aad_a).is_err());
158158
}
159+
160+
#[test]
161+
fn decrypt_v031_storable() {
162+
// This test ensures backward compatibility with v0.3.1 Storables.
163+
// In v0.3.1, the AAD was hardcoded to empty (&[]), so we must pass an empty AAD
164+
// when decrypting v0.3.1 Storables to maintain compatibility.
165+
let test_entropy_provider = TestEntropyProvider;
166+
let mut data_key = [0u8; 32];
167+
test_entropy_provider.fill_bytes(&mut data_key);
168+
let storable_builder = StorableBuilder::new(test_entropy_provider);
169+
170+
// This Storable was generated using v0.3.1 with:
171+
// - data: b"backward_compat_test_data"
172+
// - version: 42
173+
// - data_encryption_key: same as data_key above
174+
// - aad: &[] (hardcoded in v0.3.1)
175+
let v031_serialized = vec![
176+
0x0a, 0x1d, 0x32, 0x19, 0xe9, 0xfb, 0x45, 0xd7, 0x42, 0xf5, 0x6c, 0x40, 0x1b, 0x74,
177+
0x13, 0xe7, 0xae, 0x07, 0xfd, 0x81, 0xe1, 0x43, 0x3a, 0xf2, 0x86, 0x3c, 0xe8, 0x8f,
178+
0x01, 0xf8, 0x6c, 0x12, 0x32, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x43, 0x68, 0x61, 0x32,
179+
0x30, 0x50, 0x6f, 0x6c, 0x79, 0x31, 0x33, 0x30, 0x35, 0x12, 0x0c, 0x00, 0x00, 0x00,
180+
0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x1a, 0x10, 0x87, 0x16, 0x35,
181+
0x02, 0x26, 0x1e, 0x30, 0xec, 0x7c, 0xf1, 0x4b, 0x79, 0x70, 0xa2, 0x41, 0x16,
182+
];
183+
184+
let v031_storable = Storable::decode(&v031_serialized[..]).unwrap();
185+
186+
// Decrypt with empty AAD to match v0.3.1 behavior
187+
let (actual_data, actual_version) =
188+
storable_builder.deconstruct(v031_storable, &data_key, &[]).unwrap();
189+
190+
assert_eq!(actual_data, b"backward_compat_test_data".to_vec());
191+
assert_eq!(actual_version, 42);
192+
}
159193
}

0 commit comments

Comments
 (0)