@@ -7,13 +7,23 @@ use std::borrow::Borrow;
77use std:: io;
88use std:: io:: { Error , ErrorKind } ;
99
10+ /// [`StorableBuilder`] is a helper utility to build and deconstruct [`Storable`] objects.
11+ /// It provides client-side `Encrypt-then-MAC` using ChaCha20-Poly1305.
1012pub struct StorableBuilder {
1113 data_encryption_key : [ u8 ; 32 ] ,
1214}
1315
1416const CHACHA20_CIPHER_NAME : & ' static str = "ChaCha20Poly1305" ;
1517
1618impl StorableBuilder {
19+
20+ /// Creates a [`Storable`] that can be serialized and stored as `value` in [PutObjectRequest].
21+ ///
22+ /// Uses ChaCha20 for encrypting the `input` and Poly1305 for generating mac/tag.
23+ ///
24+ /// Refer to docs on [`Storable`] for more information.
25+ ///
26+ /// [PutObjectRequest]: crate::types::PutObjectRequest
1727 pub fn build ( & self , input : Vec < u8 > , version : i64 ) -> Storable {
1828 let mut rng = ThreadRng :: default ( ) ;
1929 let mut nonce = [ 0u8 ; 12 ] ;
@@ -34,6 +44,10 @@ impl StorableBuilder {
3444 }
3545 }
3646
47+ /// Deconstructs the provided [`Storable`] and returns constituent decrypted data and it's
48+ /// corresponding version as stored at the time of [PutObjectRequest].
49+ ///
50+ /// [PutObjectRequest]: crate::types::PutObjectRequest
3751 pub fn deconstruct ( & self , mut storable : Storable ) -> io:: Result < ( Vec < u8 > , i64 ) > {
3852 let encryption_metadata = storable. encryption_metadata . unwrap ( ) ;
3953 let mut cipher = ChaCha20Poly1305 :: new ( & self . data_encryption_key , & encryption_metadata. nonce , & [ ] ) ;
0 commit comments