From 7a636d3244668845c6f8a897f3ae0b21dd27cf30 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 24 Aug 2018 02:14:16 +0200 Subject: [PATCH] remove unnecessary mutable borrows in API Thanks, @aep. Fixes #32 --- Cargo.toml | 2 +- src/session.rs | 14 +++++++------- src/stateless_transportstate.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7202062a..acfbd29d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "A pure-rust implementation of the Noise Protocol Framework" homepage = "https://snow.rs" documentation = "https://snow.rs/doc/snow" repository = "https://github.com/mcginty/snow" -version = "0.4.0-alpha1" +version = "0.4.0-alpha2" authors = ["Jake McGinty ", "trevp"] license = "Unlicense" categories = ["cryptography"] diff --git a/src/session.rs b/src/session.rs index 39d2bac7..b35f178d 100644 --- a/src/session.rs +++ b/src/session.rs @@ -109,10 +109,10 @@ impl Session { /// /// Will result in `SnowError::StateProblem` if not in stateless transport mode. #[must_use] - pub fn write_message_with_nonce(&mut self, nonce: u64, payload: &[u8], output: &mut [u8]) -> Result { + pub fn write_message_with_nonce(&self, nonce: u64, payload: &[u8], output: &mut [u8]) -> Result { match *self { - Session::StatelessTransport(ref mut state) => state.write_transport_message(nonce, payload, output), - _ => bail!(StateProblem::StatelessTransportMode), + Session::StatelessTransport(ref state) => state.write_transport_message(nonce, payload, output), + _ => bail!(StateProblem::StatelessTransportMode), } } @@ -149,10 +149,10 @@ impl Session { /// /// Will result in `SnowError::StateProblem` if not in stateless transport mode. #[must_use] - pub fn read_message_with_nonce(&mut self, nonce: u64, input: &[u8], payload: &mut [u8]) -> Result { + pub fn read_message_with_nonce(&self, nonce: u64, input: &[u8], payload: &mut [u8]) -> Result { match *self { - Session::StatelessTransport(ref mut state) => state.read_transport_message(nonce, input, payload), - _ => bail!(StateProblem::StatelessTransportMode), + Session::StatelessTransport(ref state) => state.read_transport_message(nonce, input, payload), + _ => bail!(StateProblem::StatelessTransportMode), } } @@ -339,4 +339,4 @@ impl TryFrom for StatelessTransportState { fn try_from(old: HandshakeState) -> Result { StatelessTransportState::new(old) } -} \ No newline at end of file +} diff --git a/src/stateless_transportstate.rs b/src/stateless_transportstate.rs index 05ec1899..8f5b6623 100644 --- a/src/stateless_transportstate.rs +++ b/src/stateless_transportstate.rs @@ -42,7 +42,7 @@ impl StatelessTransportState { self.rs.as_option_ref().map(|rs| &rs[..self.dh_len]) } - pub fn write_transport_message(&mut self, + pub fn write_transport_message(&self, nonce: u64, payload: &[u8], message: &mut [u8]) -> Result { @@ -52,7 +52,7 @@ impl StatelessTransportState { bail!(SnowError::Input); } - let cipher = if self.initiator { &mut self.cipherstates.0 } else { &mut self.cipherstates.1 }; + let cipher = if self.initiator { &self.cipherstates.0 } else { &self.cipherstates.1 }; Ok(cipher.encrypt(nonce, payload, message)) }