@@ -33,20 +33,22 @@ use crate::prelude::*;
33
33
/// ## Example
34
34
/// ```ignore
35
35
/// 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] );
39
39
/// ```
40
40
#[ derive( PartialEq ) ]
41
41
pub struct OurPeerStorage {
42
42
encrypted_data : Vec < u8 > ,
43
43
}
44
44
45
45
impl OurPeerStorage {
46
+ /// Creates a new [`OurPeerStorage`] with given encrypted_data.
46
47
pub fn new ( encrypted_data : Vec < u8 > ) -> Self {
47
48
Self { encrypted_data }
48
49
}
49
50
51
+ /// Get encrypted data stored inside [`OurPeerStorage`].
50
52
pub fn encrypted_data ( & self ) -> Vec < u8 > {
51
53
self . encrypted_data . clone ( )
52
54
}
@@ -76,7 +78,7 @@ impl OurPeerStorage {
76
78
77
79
/// Decrypt `OurPeerStorage` using the `key`, result is stored inside the `res`.
78
80
/// 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 > , ( ) > {
80
82
const MIN_CYPHERTEXT_LEN : usize = 16 ;
81
83
let cyphertext = & self . encrypted_data [ ..] ;
82
84
0 commit comments