pub struct EphemeralServer { /* private fields */ }Expand description
Generate per request. Do not reuse.
Implementations§
Source§impl EphemeralServer
 
impl EphemeralServer
Sourcepub fn new() -> Result<Self, Unspecified>
 
pub fn new() -> Result<Self, Unspecified>
Examples found in repository?
examples/assertions.rs (line 16)
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}Sourcepub fn encrypt_secret(
    self,
    req: &ClientReq,
    plaintext: &[u8],
) -> Result<ServerEncryptedRes, Unspecified>
 
pub fn encrypt_secret( self, req: &ClientReq, plaintext: &[u8], ) -> Result<ServerEncryptedRes, Unspecified>
consume self to force not reusing keys
Examples found in repository?
examples/assertions.rs (line 17)
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 EphemeralServer
impl RefUnwindSafe for EphemeralServer
impl Send for EphemeralServer
impl Sync for EphemeralServer
impl Unpin for EphemeralServer
impl UnwindSafe for EphemeralServer
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