@@ -20,10 +20,12 @@ use aws_sdk_dynamodb::types::{AttributeValue, Delete, Put, TransactWriteItem};
2020use cipherstash_client:: {
2121 config:: {
2222 console_config:: ConsoleConfig , cts_config:: CtsConfig , zero_kms_config:: ZeroKMSConfig ,
23+ EnvSource ,
2324 } ,
24- credentials:: { auto_refresh:: AutoRefresh , service_credentials :: ServiceCredentials } ,
25+ credentials:: { auto_refresh:: AutoRefresh , ServiceCredentials } ,
2526 encryption:: ScopedCipher ,
26- zerokms:: { ClientKey , ZeroKMS , ZeroKMSWithClientKey } ,
27+ zerokms:: { ClientKey , ZeroKMSWithClientKey } ,
28+ IdentifiedBy ,
2729} ;
2830use log:: info;
2931use std:: {
@@ -73,7 +75,7 @@ impl EncryptedTable<Headless> {
7375
7476 let zerokms_config = ZeroKMSConfig :: builder ( )
7577 . decryption_log ( true )
76- . with_env ( )
78+ . add_source ( EnvSource :: default ( ) )
7779 . console_config ( & console_config)
7880 . cts_config ( & cts_config)
7981 . build_with_client_key ( ) ?;
@@ -86,12 +88,8 @@ impl EncryptedTable<Headless> {
8688 ) -> Result < Self , InitError > {
8789 info ! ( "Initializing..." ) ;
8890
89- let cipher = ZeroKMS :: new_with_client_key (
90- & zerokms_config. base_url ( ) ,
91- AutoRefresh :: new ( zerokms_config. credentials ( ) ) ,
92- zerokms_config. decryption_log_path ( ) . as_deref ( ) ,
93- zerokms_config. client_key ( ) ,
94- ) ;
91+ let cipher = zerokms_config
92+ . create_client_with_credentials ( AutoRefresh :: new ( zerokms_config. credentials ( ) ) ) ;
9593
9694 info ! ( "Ready!" ) ;
9795
@@ -312,7 +310,8 @@ impl<D> EncryptedTable<D> {
312310 delete : PreparedDelete ,
313311 dataset_id : Option < DatasetId > ,
314312 ) -> Result < DynamoRecordPatch , DeleteError > {
315- let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await ?;
313+ let keyset_id = dataset_id. map ( |id| IdentifiedBy :: Uuid ( id) ) ;
314+ let scoped_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , keyset_id) . await ?;
316315
317316 let PrimaryKeyParts { pk, sk } =
318317 encrypt_primary_key_parts ( & scoped_cipher, delete. primary_key ) ?;
@@ -352,7 +351,8 @@ impl<D> EncryptedTable<D> {
352351 ) -> Result < DynamoRecordPatch , PutError > {
353352 let mut seen_sk = HashSet :: new ( ) ;
354353
355- let indexable_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await ?;
354+ let keyset_id = dataset_id. map ( |id| IdentifiedBy :: Uuid ( id) ) ;
355+ let indexable_cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , keyset_id) . await ?;
356356
357357 let PreparedRecord {
358358 protected_attributes,
@@ -463,7 +463,8 @@ impl EncryptedTable<Dynamo> {
463463 where
464464 T : Decryptable + Identifiable ,
465465 {
466- let cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , dataset_id) . await ?;
466+ let keyset_id = dataset_id. map ( |id| IdentifiedBy :: Uuid ( id) ) ;
467+ let cipher = ScopedZeroKmsCipher :: init ( self . cipher . clone ( ) , keyset_id) . await ?;
467468
468469 let PrimaryKeyParts { pk, sk } =
469470 encrypt_primary_key_parts ( & cipher, PreparedPrimaryKey :: new :: < T > ( k) ) ?;
0 commit comments