Skip to content

Commit

Permalink
remove unnecessary mutable borrows in API
Browse files Browse the repository at this point in the history
Thanks, @aep.
Fixes #32
  • Loading branch information
mcginty committed Aug 24, 2018
1 parent 3ed331a commit 7a636d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>", "trevp"]
license = "Unlicense"
categories = ["cryptography"]
Expand Down
14 changes: 7 additions & 7 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, SnowError> {
pub fn write_message_with_nonce(&self, nonce: u64, payload: &[u8], output: &mut [u8]) -> Result<usize, SnowError> {
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),
}
}

Expand Down Expand Up @@ -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<usize, SnowError> {
pub fn read_message_with_nonce(&self, nonce: u64, input: &[u8], payload: &mut [u8]) -> Result<usize, SnowError> {
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),
}
}

Expand Down Expand Up @@ -339,4 +339,4 @@ impl TryFrom<HandshakeState> for StatelessTransportState {
fn try_from(old: HandshakeState) -> Result<Self, Self::Error> {
StatelessTransportState::new(old)
}
}
}
4 changes: 2 additions & 2 deletions src/stateless_transportstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, SnowError> {
Expand All @@ -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))
}

Expand Down

0 comments on commit 7a636d3

Please sign in to comment.