Skip to content

Commit

Permalink
Merge pull request #79 from Kuska-ssb/fix/clippy
Browse files Browse the repository at this point in the history
Fix clippy lints
  • Loading branch information
Dhole authored Oct 14, 2021
2 parents 500df05 + 70bae7a commit 94614ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/async_std/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ pub async fn handshake_client<T: Read + Write + Unpin>(

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_client_hello(&mut send_buf);
stream.write_all(&send_buf).await?;
stream.write_all(send_buf).await?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf).await?;
let handshake = handshake.recv_server_hello(&recv_buf)?;
let handshake = handshake.recv_server_hello(recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_client_auth(&mut send_buf, server_pk)?;
stream.write_all(&send_buf).await?;
stream.write_all(send_buf).await?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf).await?;
Expand All @@ -62,19 +62,19 @@ pub async fn handshake_server<T: Read + Write + Unpin>(

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf).await?;
let handshake = handshake.recv_client_hello(&recv_buf)?;
let handshake = handshake.recv_client_hello(recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_server_hello(&mut send_buf);
stream.write_all(&send_buf).await?;
stream.write_all(send_buf).await?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf).await?;
let handshake = handshake.recv_client_auth(&mut recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_server_accept(&mut send_buf);
stream.write_all(&send_buf).await?;
stream.write_all(send_buf).await?;

Ok(handshake.complete())
}
Expand Down
9 changes: 3 additions & 6 deletions src/boxstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ impl BoxStreamSend {
return Err(Error::GoodbyeSent);
}
self.goodbye = true;
Ok(encrypt_box_stream_goodbye(
&mut self.key_nonce,
&mut enc[..],
))
Ok(encrypt_box_stream_goodbye(&mut self.key_nonce, enc))
}

/// Returns whether the goodbye message has been sent or not.
Expand Down Expand Up @@ -251,7 +248,7 @@ fn decrypt_box_stream_header(
buf[..MSG_HEADER_LEN].split_at_mut(secretbox::MACBYTES);
match secretbox::open_detached(
&mut header_body_buf,
&secretbox::Tag::from_slice(&header_tag_buf).unwrap(),
&secretbox::Tag::from_slice(header_tag_buf).unwrap(),
&key_nonce.nonce,
&key_nonce.key,
) {
Expand All @@ -261,7 +258,7 @@ fn decrypt_box_stream_header(
Ok(Decrypted::Goodbye)
} else {
Ok(Decrypted::Some(
Header::from_slice(&header_body_buf).unwrap(),
Header::from_slice(header_body_buf).unwrap(),
))
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Handshake<RecvServerAccept> {
let (tag_buf, mut enc_buf) = recv_buf.split_at_mut(secretbox::MACBYTES);
secretbox::open_detached(
&mut enc_buf,
&secretbox::Tag::from_slice(&tag_buf).unwrap(),
&secretbox::Tag::from_slice(tag_buf).unwrap(),
&secretbox::Nonce([0; 24]),
&secretbox::Key(
sha256::hash(
Expand All @@ -333,7 +333,7 @@ impl Handshake<RecvServerAccept> {
)
.or(Err(Error::RecvServerAcceptSecretbox))?;
let dec_buf = enc_buf;
let sig = ed25519::Signature::from_slice(&dec_buf).unwrap();
let sig = ed25519::Signature::from_slice(dec_buf).unwrap();
if !ed25519::verify_detached(
&sig,
&[
Expand Down Expand Up @@ -450,7 +450,7 @@ impl Handshake<RecvClientAuth> {
let (tag_buf, mut enc_buf) = recv_buf.split_at_mut(secretbox::MACBYTES);
secretbox::open_detached(
&mut enc_buf,
&secretbox::Tag::from_slice(&tag_buf).unwrap(),
&secretbox::Tag::from_slice(tag_buf).unwrap(),
&secretbox::Nonce([0; 24]),
&secretbox::Key(
sha256::hash(
Expand Down
12 changes: 6 additions & 6 deletions src/sync/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ pub fn handshake_client<T: Read + Write>(

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_client_hello(&mut send_buf);
stream.write_all(&send_buf)?;
stream.write_all(send_buf)?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf)?;
let handshake = handshake.recv_server_hello(&recv_buf)?;
let handshake = handshake.recv_server_hello(recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_client_auth(&mut send_buf, server_pk)?;
stream.write_all(&send_buf)?;
stream.write_all(send_buf)?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf)?;
Expand All @@ -61,19 +61,19 @@ pub fn handshake_server<T: Read + Write>(

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf)?;
let handshake = handshake.recv_client_hello(&recv_buf)?;
let handshake = handshake.recv_client_hello(recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_server_hello(&mut send_buf);
stream.write_all(&send_buf)?;
stream.write_all(send_buf)?;

let mut recv_buf = &mut buf[..handshake.recv_bytes()];
stream.read_exact(&mut recv_buf)?;
let handshake = handshake.recv_client_auth(&mut recv_buf)?;

let mut send_buf = &mut buf[..handshake.send_bytes()];
let handshake = handshake.send_server_accept(&mut send_buf);
stream.write_all(&send_buf)?;
stream.write_all(send_buf)?;

Ok(handshake.complete())
}
Expand Down

0 comments on commit 94614ed

Please sign in to comment.