1010//! `OurPeerStorage` enables versioned storage of serialized channel data.
1111//! It supports encryption and decryption to maintain data integrity and security during
1212//! transmission.
13+ //!
14+ use crate :: chain:: chainmonitor:: PeerStorageKey ;
1315
1416use crate :: crypto:: chacha20poly1305rfc:: ChaCha20Poly1305RFC ;
1517use crate :: prelude:: * ;
@@ -60,15 +62,15 @@ impl OurPeerStorage {
6062 /// (serialised channel information), and returns a serialised [`OurPeerStorage`] as a `Vec<u8>`.
6163 ///
6264 /// The resulting serialised data is intended to be directly used for transmission to the peers.
63- pub fn create_from_data ( key : [ u8 ; 32 ] , mut ser_channels : Vec < u8 > ) -> OurPeerStorage {
65+ pub fn create_from_data ( key : PeerStorageKey , mut ser_channels : Vec < u8 > ) -> OurPeerStorage {
6466 let n = 0u64 ;
6567
6668 let plaintext_len = ser_channels. len ( ) ;
6769
6870 let mut nonce = [ 0 ; 12 ] ;
6971 nonce[ 4 ..] . copy_from_slice ( & n. to_le_bytes ( ) [ ..] ) ;
7072
71- let mut chacha = ChaCha20Poly1305RFC :: new ( & key, & nonce, b"" ) ;
73+ let mut chacha = ChaCha20Poly1305RFC :: new ( key. as_bytes ( ) , & nonce, b"" ) ;
7274 let mut tag = [ 0 ; 16 ] ;
7375 chacha. encrypt_full_message_in_place ( & mut ser_channels[ 0 ..plaintext_len] , & mut tag) ;
7476
@@ -79,7 +81,7 @@ impl OurPeerStorage {
7981
8082 /// Decrypt `OurPeerStorage` using the `key`, result is stored inside the `res`.
8183 /// Returns an error if the the `cyphertext` is not correct.
82- pub fn decrypt_our_peer_storage ( mut self , key : [ u8 ; 32 ] ) -> Result < Vec < u8 > , ( ) > {
84+ pub fn decrypt_our_peer_storage ( mut self , key : PeerStorageKey ) -> Result < Vec < u8 > , ( ) > {
8385 const MIN_CYPHERTEXT_LEN : usize = 16 ;
8486 let cyphertext_len = self . encrypted_data . len ( ) ;
8587
@@ -95,7 +97,7 @@ impl OurPeerStorage {
9597 let mut nonce = [ 0 ; 12 ] ;
9698 nonce[ 4 ..] . copy_from_slice ( & n. to_le_bytes ( ) [ ..] ) ;
9799
98- let mut chacha = ChaCha20Poly1305RFC :: new ( & key, & nonce, b"" ) ;
100+ let mut chacha = ChaCha20Poly1305RFC :: new ( key. as_bytes ( ) , & nonce, b"" ) ;
99101
100102 if chacha. check_decrypt_in_place ( encrypted_data, tag) . is_err ( ) {
101103 return Err ( ( ) ) ;
0 commit comments