@@ -18,18 +18,21 @@ use crate::{
1818} ; 
1919use  aws_sdk_dynamodb:: types:: { AttributeValue ,  Delete ,  Put ,  TransactWriteItem } ; 
2020use  cipherstash_client:: { 
21-     config:: { console_config:: ConsoleConfig ,  cts_config:: CtsConfig ,  zero_kms_config:: ZeroKMSConfig } ,  credentials:: { 
22-         auto_refresh:: AutoRefresh , 
23-         service_credentials:: ServiceCredentials , 
24-     } ,  encryption:: ScopedCipher ,  zerokms:: { ZeroKMS ,  ZeroKMSWithClientKey } 
21+     config:: { 
22+         console_config:: ConsoleConfig ,  cts_config:: CtsConfig ,  zero_kms_config:: ZeroKMSConfig , 
23+     } , 
24+     credentials:: { auto_refresh:: AutoRefresh ,  service_credentials:: ServiceCredentials } , 
25+     encryption:: ScopedCipher , 
26+     zerokms:: { ZeroKMS ,  ZeroKMSWithClientKey } , 
2527} ; 
2628use  log:: info; 
27- use  uuid:: Uuid ; 
2829use  std:: { 
2930    borrow:: Cow , 
3031    collections:: { HashMap ,  HashSet } , 
31-     ops:: Deref ,  sync:: Arc , 
32+     ops:: Deref , 
33+     sync:: Arc , 
3234} ; 
35+ use  uuid:: Uuid ; 
3336
3437pub  struct  Headless ; 
3538
@@ -274,7 +277,8 @@ impl<D> EncryptedTable<D> {
274277        & self , 
275278        items :  impl  IntoIterator < Item  = HashMap < String ,  AttributeValue > > , 
276279    )  -> Result < Vec < T > ,  DecryptError > 
277-     where  T :  Decryptable  + Identifiable , 
280+     where 
281+         T :  Decryptable  + Identifiable , 
278282    { 
279283        decrypt_all ( & self . cipher ,  items) . await 
280284    } 
@@ -284,13 +288,18 @@ impl<D> EncryptedTable<D> {
284288        delete :  PreparedDelete , 
285289        dataset_id :  Option < Uuid > , 
286290    )  -> Result < DynamoRecordPatch ,  DeleteError >  { 
287-         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  dataset_id) . await . unwrap ( ) ; 
291+         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  dataset_id) 
292+             . await 
293+             . unwrap ( ) ; 
288294
289-         let  PrimaryKeyParts  {  pk,  sk }  = encrypt_primary_key_parts ( & scoped_cipher,  delete. primary_key ) ?; 
295+         let  PrimaryKeyParts  {  pk,  sk }  =
296+             encrypt_primary_key_parts ( & scoped_cipher,  delete. primary_key ) ?; 
290297
291298        let  delete_records = all_index_keys ( & sk,  delete. protected_indexes ) 
292299            . into_iter ( ) 
293-             . map ( |x| Ok :: < _ ,  DeleteError > ( b64_encode ( scoped_cipher. mac :: < 32 > ( & x,  Some ( pk. as_str ( ) ) ) ) ) ) 
300+             . map ( |x| { 
301+                 Ok :: < _ ,  DeleteError > ( b64_encode ( scoped_cipher. mac :: < 32 > ( & x,  Some ( pk. as_str ( ) ) ) ) ) 
302+             } ) 
294303            . chain ( [ Ok ( sk) ] ) 
295304            . map ( |sk| { 
296305                let  sk = sk?; 
@@ -330,9 +339,7 @@ impl<D> EncryptedTable<D> {
330339        }  = record; 
331340
332341        // Do the encryption 
333-         let  sealed = sealer
334-             . seal ( protected_attributes,  & indexable_cipher) 
335-             . await ?; 
342+         let  sealed = sealer. seal ( protected_attributes,  & indexable_cipher) . await ?; 
336343
337344        let  mut  put_records = Vec :: with_capacity ( sealed. len ( ) ) ; 
338345
@@ -395,20 +402,32 @@ impl EncryptedTable<Dynamo> {
395402        T :  Decryptable  + Identifiable , 
396403    { 
397404        // TODO: Don't unwrap 
398-         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  None ) . await . unwrap ( ) ; 
405+         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  None ) 
406+             . await 
407+             . unwrap ( ) ; 
399408        self . get_inner ( k,  scoped_cipher) . await 
400409    } 
401410
402-     pub  async  fn  get_via < T > ( & self ,  k :  impl  Into < T :: PrimaryKey > ,  dataset_id :  Uuid )  -> Result < Option < T > ,  GetError > 
411+     pub  async  fn  get_via < T > ( 
412+         & self , 
413+         k :  impl  Into < T :: PrimaryKey > , 
414+         dataset_id :  Uuid , 
415+     )  -> Result < Option < T > ,  GetError > 
403416    where 
404417        T :  Decryptable  + Identifiable , 
405418    { 
406419        // TODO: Don't unwrap 
407-         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  Some ( dataset_id) ) . await . unwrap ( ) ; 
420+         let  scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) ,  Some ( dataset_id) ) 
421+             . await 
422+             . unwrap ( ) ; 
408423        self . get_inner ( k,  scoped_cipher) . await 
409424    } 
410425
411-     async  fn  get_inner < T > ( & self ,  k :  impl  Into < T :: PrimaryKey > ,  cipher :  ScopedZeroKmsCipher )  -> Result < Option < T > ,  GetError > 
426+     async  fn  get_inner < T > ( 
427+         & self , 
428+         k :  impl  Into < T :: PrimaryKey > , 
429+         cipher :  ScopedZeroKmsCipher , 
430+     )  -> Result < Option < T > ,  GetError > 
412431    where 
413432        T :  Decryptable  + Identifiable , 
414433    { 
@@ -513,7 +532,6 @@ impl EncryptedTable<Dynamo> {
513532    } 
514533} 
515534
516- 
517535/// Take a prepared primary key and encrypt it to get the [`PrimaryKeyParts`] which can be used 
518536/// for retrieval. 
519537fn  encrypt_primary_key_parts ( 
@@ -533,13 +551,16 @@ fn encrypt_primary_key_parts(
533551    Ok ( PrimaryKeyParts  {  pk,  sk } ) 
534552} 
535553
536- async  fn  decrypt < T > ( scoped_cipher :  & ZeroKmsCipher ,  item :  HashMap < String ,  AttributeValue > )  -> Result < T ,  DecryptError > 
554+ async  fn  decrypt < T > ( 
555+     scoped_cipher :  & ZeroKmsCipher , 
556+     item :  HashMap < String ,  AttributeValue > , 
557+ )  -> Result < T ,  DecryptError > 
537558where 
538559    T :  Decryptable  + Identifiable , 
539560{ 
540561    let  uspec = UnsealSpec :: new_for_decryptable :: < T > ( ) ; 
541562    let  table_entry = SealedTableEntry :: try_from ( item) ?; 
542-          let  result = table_entry. unseal ( uspec,  scoped_cipher) . await ?; 
563+     let  result = table_entry. unseal ( uspec,  scoped_cipher) . await ?; 
543564
544565    Ok ( result. into_value ( ) ?) 
545566} 
0 commit comments