diff options
author | Jake McGinty <me@jake.su> | 2018-02-06 01:02:24 +0000 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-02-06 01:02:26 +0000 |
commit | b2fcc0bc211603966acb5d0fb9dfcbd6d3fc1d33 (patch) | |
tree | 7205518ecc348ea45c18e2ae16e5aa02c58d9075 /src | |
parent | add sopium's AntiReplay struct and implement it for transport packets (diff) | |
download | wireguard-rs-b2fcc0bc211603966acb5d0fb9dfcbd6d3fc1d33.tar.xz wireguard-rs-b2fcc0bc211603966acb5d0fb9dfcbd6d3fc1d33.zip |
only allocate space to decrypt a packet if session exists
Diffstat (limited to 'src')
-rw-r--r-- | src/protocol/peer.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/protocol/peer.rs b/src/protocol/peer.rs index d4b6b40..a44dffd 100644 --- a/src/protocol/peer.rs +++ b/src/protocol/peer.rs @@ -116,7 +116,6 @@ impl Peer { } pub fn decrypt_transport_packet(&mut self, our_index: u32, nonce: u64, packet: &[u8]) -> Result<Vec<u8>, ()> { - let mut raw_packet = vec![0u8; 1500]; self.rx_bytes += packet.len() as u64; let session = self.sessions.current.as_mut().filter(|session| session.our_index == our_index) @@ -124,6 +123,7 @@ impl Peer { .ok_or_else(|| ())?; if session.anti_replay.check_and_update(nonce) { + let mut raw_packet = vec![0u8; 1500]; session.noise.set_receiving_nonce(nonce).unwrap(); let len = session.noise.read_message(packet, &mut raw_packet).map_err(|_| ())?; raw_packet.truncate(len); |