veil_seal_open/
veil_seal_open.rs1use bincode::{Encode, Decode};
15use toolkit_zero::serialization::{seal, open};
16
17#[derive(Debug, PartialEq, Encode, Decode)]
19struct Payload {
20 user: String,
21 score: u32,
22 tags: Vec<String>,
23}
24
25fn main() {
26 let key = "my-secret-key";
27
28 let original = Payload {
29 user: "alice".into(),
30 score: 9001,
31 tags: vec!["rust".into(), "crypto".into()],
32 };
33
34 println!("Original : {original:?}");
35
36 let blob = seal(&original, Some(key.to_string())).expect("seal failed");
39 println!("Sealed : {} bytes (opaque — no structure visible)", blob.len());
40
41 let recovered: Payload = open(&blob, Some(key.to_string())).expect("open failed");
44 println!("Recovered: {recovered:?}");
45
46 assert_eq!(original, recovered, "round-trip mismatch!");
47 println!("\nRound-trip successful ✓");
48
49 let bad: Result<Payload, _> = open(&blob, Some("wrong-key".to_string()));
51 assert!(bad.is_err(), "wrong key should fail to open");
52 println!("Wrong-key rejection ✓");
53}