Skip to content

Commit 8873d3a

Browse files
committed
appease Rust 1.22 by using byte_utils for endianness functionality
1 parent 2e9be87 commit 8873d3a

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
519519
}
520520
}
521521

522-
if let &PeerState::Handshake(ref mut handshake) = &mut peer.encryptor {
522+
if let &mut PeerState::Handshake(ref mut handshake) = &mut peer.encryptor {
523523
let (response, conduit, remote_pubkey) = handshake.process_act(&peer.pending_read_buffer, None).unwrap();
524524
peer.pending_read_buffer.drain(..); // we read it all
525525

@@ -529,7 +529,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
529529
}
530530
}
531531

532-
if let &PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
532+
if let &mut PeerState::Connected(ref mut conduit) = &mut peer.encryptor {
533533
let mut messages = conduit.decrypt_message_stream(Some(&peer.pending_read_buffer));
534534

535535
if messages.len() != 1 {

lightning/src/ln/peers/chacha.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use util::byte_utils;
12
use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
23

34
pub fn encrypt(key: &[u8], nonce: u64, associated_data: &[u8], plaintext: &[u8]) -> Vec<u8> {
45
let mut nonce_bytes = [0; 12];
5-
nonce_bytes[4..].copy_from_slice(&nonce.to_le_bytes());
6+
nonce_bytes[4..].copy_from_slice(&byte_utils::le64_to_array(nonce));
67

78
let mut chacha = ChaCha20Poly1305RFC::new(key, &nonce_bytes, associated_data);
89
let mut ciphertext = vec![0u8; plaintext.len()];
@@ -17,7 +18,7 @@ pub fn encrypt(key: &[u8], nonce: u64, associated_data: &[u8], plaintext: &[u8])
1718

1819
pub fn decrypt(key: &[u8], nonce: u64, associated_data: &[u8], tagged_ciphertext: &[u8]) -> Result<Vec<u8>, String> {
1920
let mut nonce_bytes = [0; 12];
20-
nonce_bytes[4..].copy_from_slice(&nonce.to_le_bytes());
21+
nonce_bytes[4..].copy_from_slice(&byte_utils::le64_to_array(nonce));
2122

2223
let length = tagged_ciphertext.len();
2324
let ciphertext = &tagged_ciphertext[0..length - 16];

lightning/src/ln/peers/conduit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Handles all over the wire message encryption and decryption upon handshake completion.
22
33
use ln::peers::{chacha, hkdf};
4+
use util::byte_utils;
45

56
/// Returned after a successful handshake to encrypt and decrypt communication with peer nodes
67
/// Automatically handles key rotation.
@@ -22,7 +23,7 @@ impl Conduit {
2223
/// Encrypt data to be sent to peer
2324
pub fn encrypt(&mut self, buffer: &[u8]) -> Vec<u8> {
2425
let length = buffer.len() as u16;
25-
let length_bytes = length.to_be_bytes();
26+
let length_bytes = byte_utils::be16_to_array(length);
2627

2728
let encrypted_length = chacha::encrypt(&self.sending_key, self.sending_nonce as u64, &[0; 0], &length_bytes);
2829
self.increment_sending_nonce();

lightning/src/ln/peers/handshake/acts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum Act {
2323
impl Act {
2424
/// Convert any act into a byte vector
2525
pub fn serialize(&self) -> Vec<u8> {
26-
match self {
26+
match &self {
2727
&Act::One(act) => {
2828
act.0.to_vec()
2929
}

0 commit comments

Comments
 (0)