EphemeralServer

Struct EphemeralServer 

Source
pub struct EphemeralServer { /* private fields */ }
Expand description

Generate per request. Do not reuse.

Implementations§

Source§

impl EphemeralServer

Source

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}
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V