@@ -279,20 +279,14 @@ impl<D> EncryptedTable<D> {
279279 ) -> Result < Vec < T > , DecryptError >
280280 where T : Decryptable + Identifiable ,
281281 {
282- // TODO: Decryption _may_ not need to be scoped
283- // TODO: Temporary obvs
284- let dataset_id = Uuid :: parse_str ( "93e10481-2692-4d65-a619-37e36a496e64" ) . unwrap ( ) ;
285- let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await . unwrap ( ) ;
286-
287- decrypt_all ( & scoped_cipher, items) . await
282+ decrypt_all ( & self . cipher , items) . await
288283 }
289284
290285 pub async fn create_delete_patch (
291286 & self ,
292287 delete : PreparedDelete ,
288+ dataset_id : Option < Uuid > ,
293289 ) -> Result < DynamoRecordPatch , DeleteError > {
294- // TODO: Temporary obvs
295- let dataset_id = Uuid :: parse_str ( "93e10481-2692-4d65-a619-37e36a496e64" ) . unwrap ( ) ;
296290 let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await . unwrap ( ) ;
297291
298292 let PrimaryKeyParts { pk, sk } = encrypt_primary_key_parts ( & scoped_cipher, delete. primary_key ) ?;
@@ -324,14 +318,12 @@ impl<D> EncryptedTable<D> {
324318 pub async fn create_put_patch (
325319 & self ,
326320 record : PreparedRecord ,
327- dataset_id : Uuid ,
321+ dataset_id : Option < Uuid > ,
328322 // TODO: Make sure the index_predicate is used correctly
329323 index_predicate : impl FnMut ( & AttributeName , & TableAttribute ) -> bool ,
330324 ) -> Result < DynamoRecordPatch , PutError > {
331325 let mut seen_sk = HashSet :: new ( ) ;
332326
333- // TODO: Temporary obvs
334- let dataset_id = Uuid :: parse_str ( "93e10481-2692-4d65-a619-37e36a496e64" ) . unwrap ( ) ;
335327 let indexable_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await . unwrap ( ) ;
336328
337329 let PreparedRecord {
@@ -405,13 +397,26 @@ impl EncryptedTable<Dynamo> {
405397 where
406398 T : Decryptable + Identifiable ,
407399 {
408- // TODO: Temporary obvs
409- let dataset_id = Uuid :: parse_str ( "93e10481-2692-4d65-a619-37e36a496e64" ) . unwrap ( ) ;
410- let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await . unwrap ( ) ;
400+ // TODO: Don't unwrap
401+ let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , None ) . await . unwrap ( ) ;
402+ self . get_inner ( k, scoped_cipher) . await
403+ }
411404
412- let PrimaryKeyParts { pk, sk } =
413- encrypt_primary_key_parts ( & scoped_cipher, PreparedPrimaryKey :: new :: < T > ( k) ) ?;
405+ pub async fn get_via < T > ( & self , k : impl Into < T :: PrimaryKey > , dataset_id : Uuid ) -> Result < Option < T > , GetError >
406+ where
407+ T : Decryptable + Identifiable ,
408+ {
409+ // TODO: Don't unwrap
410+ let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , Some ( dataset_id) ) . await . unwrap ( ) ;
411+ self . get_inner ( k, scoped_cipher) . await
412+ }
414413
414+ async fn get_inner < T > ( & self , k : impl Into < T :: PrimaryKey > , cipher : ScopedZeroKmsCipher ) -> Result < Option < T > , GetError >
415+ where
416+ T : Decryptable + Identifiable ,
417+ {
418+ let PrimaryKeyParts { pk, sk } =
419+ encrypt_primary_key_parts ( & cipher, PreparedPrimaryKey :: new :: < T > ( k) ) ?;
415420
416421 let result = self
417422 . db
@@ -423,10 +428,8 @@ impl EncryptedTable<Dynamo> {
423428 . await
424429 . map_err ( |e| GetError :: Aws ( format ! ( "{e:?}" ) ) ) ?;
425430
426- println ! ( "RESULT {:?}" , result) ;
427-
428431 if let Some ( item) = result. item {
429- Ok ( Some ( decrypt ( & scoped_cipher , item) . await ?) )
432+ Ok ( Some ( decrypt ( & self . cipher , item) . await ?) )
430433 } else {
431434 Ok ( None )
432435 }
@@ -435,9 +438,25 @@ impl EncryptedTable<Dynamo> {
435438 pub async fn delete < E : Searchable + Identifiable > (
436439 & self ,
437440 k : impl Into < E :: PrimaryKey > ,
441+ ) -> Result < ( ) , DeleteError > {
442+ self . delete_inner :: < E > ( k. into ( ) , None ) . await
443+ }
444+
445+ pub async fn delete_via < E : Searchable + Identifiable > (
446+ & self ,
447+ k : impl Into < E :: PrimaryKey > ,
448+ dataset_id : Uuid ,
449+ ) -> Result < ( ) , DeleteError > {
450+ self . delete_inner :: < E > ( k. into ( ) , Some ( dataset_id) ) . await
451+ }
452+
453+ async fn delete_inner < E : Searchable + Identifiable > (
454+ & self ,
455+ k : E :: PrimaryKey ,
456+ dataset_id : Option < Uuid > ,
438457 ) -> Result < ( ) , DeleteError > {
439458 let transact_items = self
440- . create_delete_patch ( PreparedDelete :: new :: < E > ( k) )
459+ . create_delete_patch ( PreparedDelete :: new :: < E > ( k) , dataset_id )
441460 . await ?
442461 . into_transact_write_items ( & self . db . table_name ) ?;
443462
@@ -455,6 +474,20 @@ impl EncryptedTable<Dynamo> {
455474 }
456475
457476 pub async fn put < T > ( & self , record : T ) -> Result < ( ) , PutError >
477+ where
478+ T : Searchable + Identifiable ,
479+ {
480+ self . put_inner ( record, None ) . await
481+ }
482+
483+ pub async fn put_via < T > ( & self , record : T , dataset_id : Uuid ) -> Result < ( ) , PutError >
484+ where
485+ T : Searchable + Identifiable ,
486+ {
487+ self . put_inner ( record, Some ( dataset_id) ) . await
488+ }
489+
490+ async fn put_inner < T > ( & self , record : T , dataset_id : Option < Uuid > ) -> Result < ( ) , PutError >
458491 where
459492 T : Searchable + Identifiable ,
460493 {
@@ -463,6 +496,7 @@ impl EncryptedTable<Dynamo> {
463496 let transact_items = self
464497 . create_put_patch (
465498 record,
499+ dataset_id,
466500 // include all records in the indexes
467501 |_, _| true ,
468502 )
@@ -502,7 +536,7 @@ fn encrypt_primary_key_parts(
502536 Ok ( PrimaryKeyParts { pk, sk } )
503537}
504538
505- async fn decrypt < T > ( scoped_cipher : & ScopedZeroKmsCipher , item : HashMap < String , AttributeValue > ) -> Result < T , DecryptError >
539+ async fn decrypt < T > ( scoped_cipher : & ZeroKmsCipher , item : HashMap < String , AttributeValue > ) -> Result < T , DecryptError >
506540where
507541 T : Decryptable + Identifiable ,
508542{
@@ -514,7 +548,7 @@ where
514548}
515549
516550async fn decrypt_all < T > (
517- scoped_cipher : & ScopedZeroKmsCipher ,
551+ scoped_cipher : & ZeroKmsCipher ,
518552 items : impl IntoIterator < Item = HashMap < String , AttributeValue > > ,
519553) -> Result < Vec < T > , DecryptError >
520554where
0 commit comments