O'Reilly logo
  • Ivan Zderadicka thinks this is interesting:

let rng = rand::SystemRandom::new();

// Generate server's private key
let server_private_key =
agreement::EphemeralPrivateKey::generate
(&agreement::X25519, &rng)?;
let mut server_public_key = [0u8; agreement::PUBLIC_KEY_MAX_LEN];
let server_public_key = &mut
server_public_key[..server_private_key.public_key_len()];

// Generate server's public key
server_private_key.compute_public_key(server_public_key)?;

From

Cover of Network Programming with Rust

Note

This part is basically same in server and client - why not to put it into lib?