diff options
author | Jake McGinty <me@jake.su> | 2018-02-17 23:53:25 +0000 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-02-17 23:53:25 +0000 |
commit | 8b79846f22ed8efe0571ed7fd384b878b3bf0f2d (patch) | |
tree | 23491bc3177757563d9f5360abdbc49a1a1a97e7 /src/noise.rs | |
parent | no need to keep track of SystemTime and Instant in Peer (diff) | |
download | wireguard-rs-8b79846f22ed8efe0571ed7fd384b878b3bf0f2d.tar.xz wireguard-rs-8b79846f22ed8efe0571ed7fd384b878b3bf0f2d.zip |
just keep noise functions in module not struct
Diffstat (limited to 'src/noise.rs')
-rw-r--r-- | src/noise.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/noise.rs b/src/noise.rs index 11310ab..c8ef182 100644 --- a/src/noise.rs +++ b/src/noise.rs @@ -7,26 +7,22 @@ lazy_static! { } /// Wrapper around the `snow` library to easily setup the handshakes for WireGuard. -pub struct Noise {} -impl Noise { - fn new_foundation(local_privkey: &[u8]) -> NoiseBuilder { - NoiseBuilder::new(NOISE_PARAMS.clone()) - .local_private_key(local_privkey) - .prologue(b"WireGuard v1 zx2c4 Jason@zx2c4.com") - } - - pub fn build_initiator(local_privkey: &[u8], remote_pubkey: &[u8], psk: &Option<[u8; 32]>) -> Result<Session, Error> { - Ok(Noise::new_foundation(local_privkey) - .remote_public_key(remote_pubkey) - .psk(2, psk.as_ref().unwrap_or_else(|| &[0u8; 32])) - .build_initiator() - .map_err(SyncFailure::new)?) - } +fn new_foundation(local_privkey: &[u8]) -> NoiseBuilder { + NoiseBuilder::new(NOISE_PARAMS.clone()) + .local_private_key(local_privkey) + .prologue(b"WireGuard v1 zx2c4 Jason@zx2c4.com") +} - pub fn build_responder(local_privkey: &[u8]) -> Result<Session, Error> { - Ok(Noise::new_foundation(local_privkey) - .build_responder() - .map_err(SyncFailure::new)?) - } +pub fn build_initiator(local_privkey: &[u8], remote_pubkey: &[u8], psk: &Option<[u8; 32]>) -> Result<Session, Error> { + Ok(new_foundation(local_privkey) + .remote_public_key(remote_pubkey) + .psk(2, psk.as_ref().unwrap_or_else(|| &[0u8; 32])) + .build_initiator() + .map_err(SyncFailure::new)?) +} +pub fn build_responder(local_privkey: &[u8]) -> Result<Session, Error> { + Ok(new_foundation(local_privkey) + .build_responder() + .map_err(SyncFailure::new)?) } |