pub struct ResponseDecryptor { /* private fields */ }Implementations§
Source§impl ResponseDecryptor
impl ResponseDecryptor
Sourcepub fn decrypt(self, res: &ServerEncryptedRes) -> Result<Vec<u8>, Unspecified>
pub fn decrypt(self, res: &ServerEncryptedRes) -> Result<Vec<u8>, Unspecified>
Examples found in repository?
examples/assertions.rs (line 19)
5fn main() -> Result<(), Unspecified> {
6 let secrets: Vec<String> = (1..=100).map(|i| format!("SuperSecret #{}", i)).collect();
7
8 let mut nonce_set = HashSet::new();
9 let mut salt_set = HashSet::new();
10 let mut pubk_set = HashSet::new();
11 let mut client_pubk_set = HashSet::new();
12 for (_, secret) in secrets.iter().enumerate() {
13 let client = EphemeralClient::new()?;
14 let (req, decryptor) = client.sendable();
15
16 let server = EphemeralServer::new()?;
17 let res = server.encrypt_secret(&req, secret.as_bytes())?;
18
19 let decrypted_secret = decryptor.decrypt(&res)?;
20
21 // sanity
22
23 assert!(secret.as_bytes() != res.ciphertext);
24 assert!(secret.as_bytes() == &decrypted_secret);
25
26 // assert non repeatable
27
28 assert!(!nonce_set.contains(&res.nonce));
29 nonce_set.insert(res.nonce);
30 assert!(!salt_set.contains(&res.salt));
31 salt_set.insert(res.salt);
32 assert!(!pubk_set.contains(&res.pubk));
33 pubk_set.insert(res.pubk.clone());
34 assert!(!client_pubk_set.contains(&req.pubk));
35 client_pubk_set.insert(req.pubk.clone());
36
37 // print to see how these things look
38 println!(
39 "{} REQ:\n{}\nRES:\n{}\n",
40 secret,
41 serde_json::to_string_pretty(&req).unwrap(),
42 serde_json::to_string_pretty(&res).unwrap()
43 );
44 }
45
46 Ok(())
47}Auto Trait Implementations§
impl Freeze for ResponseDecryptor
impl RefUnwindSafe for ResponseDecryptor
impl Send for ResponseDecryptor
impl Sync for ResponseDecryptor
impl Unpin for ResponseDecryptor
impl UnwindSafe for ResponseDecryptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more