Skip to content

Commit 4adeeee

Browse files
committed
fixup: Add OurPeerStorage for serialized Peer Storage backups
1 parent 0c10bd5 commit 4adeeee

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lightning/src/ln/our_peer_storage.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ use crate::prelude::*;
3333
/// ## Example
3434
/// ```ignore
3535
/// let key = [0u8; 32];
36-
/// let mut our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1,2,3]);
37-
/// let mut decrypted = vec![0u8; encrypted.len()];
38-
/// OurPeerStorage::decrypt_our_peer_storage(&mut decrypted, &our_peer_storage, key).unwrap();
36+
/// let our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1,2,3]);
37+
/// let decrypted_data = our_peer_storage.decrypt_our_peer_storage(key).unwrap();
38+
/// assert_eq!(decrypted_data, vec![1 , 2, 3]);
3939
/// ```
4040
#[derive(PartialEq)]
4141
pub struct OurPeerStorage {
4242
encrypted_data: Vec<u8>,
4343
}
4444

4545
impl OurPeerStorage {
46+
/// Creates a new [`OurPeerStorage`] with given encrypted_data.
4647
pub fn new(encrypted_data: Vec<u8>) -> Self {
4748
Self { encrypted_data }
4849
}
4950

51+
/// Get encrypted data stored inside [`OurPeerStorage`].
5052
pub fn encrypted_data(&self) -> Vec<u8> {
5153
self.encrypted_data.clone()
5254
}
@@ -76,7 +78,7 @@ impl OurPeerStorage {
7678

7779
/// Decrypt `OurPeerStorage` using the `key`, result is stored inside the `res`.
7880
/// Returns an error if the the `cyphertext` is not correct.
79-
pub fn decrypt_our_peer_storage(&self, key: [u8; 32]) -> Result<Vec<u8>, ()> {
81+
pub fn decrypt_our_peer_storage(self, key: [u8; 32]) -> Result<Vec<u8>, ()> {
8082
const MIN_CYPHERTEXT_LEN: usize = 16;
8183
let cyphertext = &self.encrypted_data[..];
8284

0 commit comments

Comments
 (0)