Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #397 from tendermint/remove-byteorder-dependency
Browse files Browse the repository at this point in the history
Remove `byteorder` dependency
  • Loading branch information
tarcieri authored Jan 23, 2020
2 parents cde03c9 + 907e5ff commit cb5b9de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ circle-ci = { repository = "tendermint/kms" }
[dependencies]
abscissa_core = "0.5"
atomicwrites = "0.2"
byteorder = "1.2"
bytes = "0.5"
chacha20poly1305 = "0.3"
chrono = "0.4"
Expand Down
9 changes: 3 additions & 6 deletions src/connection/secret_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod public_key;

pub use self::{amino_types::AuthSigMessage, kdf::Kdf, nonce::Nonce, public_key::PublicKey};
use crate::error::{Error, ErrorKind};
use byteorder::{ByteOrder, LE};
use bytes::BufMut;
use chacha20poly1305::{
aead::{generic_array::GenericArray, Aead, NewAead},
Expand All @@ -21,6 +20,7 @@ use signatory::{
use signatory_dalek::Ed25519Verifier;
use std::{
cmp,
convert::TryInto,
io::{self, Read, Write},
marker::{Send, Sync},
};
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<IoHandler: Read + Write + Send + Sync> SecretConnection<IoHandler> {
sealed_frame: &mut [u8; TAG_SIZE + TOTAL_FRAME_SIZE],
) -> Result<(), Error> {
debug_assert!(chunk.len() <= TOTAL_FRAME_SIZE - DATA_LEN_SIZE);
LE::write_u32(&mut sealed_frame[..DATA_LEN_SIZE], chunk.len() as u32);
sealed_frame[..DATA_LEN_SIZE].copy_from_slice(&(chunk.len() as u32).to_le_bytes());
sealed_frame[DATA_LEN_SIZE..DATA_LEN_SIZE + chunk.len()].copy_from_slice(chunk);

let tag = self
Expand Down Expand Up @@ -219,10 +219,7 @@ where
self.recv_nonce.increment();
// end decryption

let mut chunk_length_specifier = vec![0; 4];
chunk_length_specifier.clone_from_slice(&frame[..4]);

let chunk_length = LE::read_u32(&chunk_length_specifier);
let chunk_length = u32::from_le_bytes(frame[..4].try_into().unwrap());

if chunk_length as usize > DATA_MAX_SIZE {
return Err(io::Error::new(
Expand Down
10 changes: 6 additions & 4 deletions src/connection/secret_connection/nonce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use byteorder::{ByteOrder, LE};
//! Secret Connection nonces
/// Size of a ChaCha20 nonce
use std::convert::TryInto;

/// Size of a ChaCha20 (IETF) nonce
pub const SIZE: usize = 12;

/// SecretConnection nonces (i.e. ChaCha20 nonces)
Expand All @@ -15,8 +17,8 @@ impl Default for Nonce {
impl Nonce {
/// Increment the nonce's counter by 1
pub fn increment(&mut self) {
let counter: u64 = LE::read_u64(&self.0[4..]);
LE::write_u64(&mut self.0[4..], counter.checked_add(1).unwrap());
let counter: u64 = u64::from_le_bytes(self.0[4..].try_into().unwrap());
self.0[4..].copy_from_slice(&counter.checked_add(1).unwrap().to_le_bytes());
}

/// Serialize nonce as bytes (little endian)
Expand Down

0 comments on commit cb5b9de

Please sign in to comment.