You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix last lint doc issue?
make the &Some matches explicit for Rust 1.22
appease Rust 1.22 some more with ampersandery
appease Rust 1.22 by using byte_utils for endianness functionality
appease Rust 1.22 by using byte_utils and ref in match arms
experimenting some more with ref matching for Rust 1.22
might Rust 1.22 finally work? Rearranged a lot of borrowing locations and macro behavior and definition locations
fix bug that was kindly caught by fuzz tests
fix fuzz test
improve error messaging
the different rust versions are a balancing act, and I can't juggle
Copy file name to clipboardExpand all lines: lightning/src/ln/peers/conduit.rs
+29-4Lines changed: 29 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,11 @@
1
+
//! Handles all over the wire message encryption and decryption upon handshake completion.
2
+
1
3
use ln::peers::{chacha, hkdf};
4
+
use util::byte_utils;
2
5
3
6
/// Returned after a successful handshake to encrypt and decrypt communication with peer nodes
7
+
/// Automatically handles key rotation.
8
+
/// For decryption, it is recommended to call `decrypt_message_stream` for automatic buffering.
4
9
pubstructConduit{
5
10
pub(crate)sending_key:[u8;32],
6
11
pub(crate)receiving_key:[u8;32],
@@ -15,9 +20,10 @@ pub struct Conduit {
15
20
}
16
21
17
22
implConduit{
23
+
/// Encrypt data to be sent to peer
18
24
pubfnencrypt(&mutself,buffer:&[u8]) -> Vec<u8>{
19
25
let length = buffer.len()asu16;
20
-
let length_bytes = length.to_be_bytes();
26
+
let length_bytes = byte_utils::be16_to_array(length);
21
27
22
28
let encrypted_length = chacha::encrypt(&self.sending_key,self.sending_nonceasu64,&[0;0],&length_bytes);
23
29
self.increment_sending_nonce();
@@ -69,7 +75,7 @@ impl Conduit {
69
75
}
70
76
71
77
/// Decrypt a single message. Buffer is an undelimited amount of bytes
72
-
fndecrypt(&mutself,buffer:&[u8]) -> (Option<Vec<u8>>,usize){// the response slice should have the same lifetime as the argument. It's the slice data is read from
78
+
pub(crate)fndecrypt(&mutself,buffer:&[u8]) -> (Option<Vec<u8>>,usize){// the response slice should have the same lifetime as the argument. It's the slice data is read from
73
79
if buffer.len() < 18{
74
80
return(None,0);
75
81
}
@@ -78,9 +84,9 @@ impl Conduit {
78
84
let length_vec = chacha::decrypt(&self.receiving_key,self.receiving_nonceasu64,&[0;0], encrypted_length).unwrap();
0 commit comments