11use crate :: {
22 crypto:: attrs:: FlattenedEncryptedAttributes ,
3- encrypted_table:: TableEntry ,
3+ encrypted_table:: { TableEntry , ZeroKmsCipher } ,
44 traits:: { ReadConversionError , WriteConversionError } ,
55 Decryptable , Identifiable ,
66} ;
77use aws_sdk_dynamodb:: { primitives:: Blob , types:: AttributeValue } ;
8- use cipherstash_client:: {
9- credentials:: { service_credentials:: ServiceToken , Credentials } ,
10- encryption:: Encryption ,
11- } ;
128use itertools:: Itertools ;
139use std:: { borrow:: Cow , collections:: HashMap } ;
1410
@@ -72,7 +68,7 @@ impl SealedTableEntry {
7268 pub ( crate ) async fn unseal_all (
7369 items : Vec < Self > ,
7470 spec : UnsealSpec < ' _ > ,
75- cipher : & Encryption < impl Credentials < Token = ServiceToken > > ,
71+ cipher : & ZeroKmsCipher ,
7672 ) -> Result < Vec < Unsealed > , SealError > {
7773 let UnsealSpec {
7874 protected_attributes,
@@ -134,7 +130,7 @@ impl SealedTableEntry {
134130 pub ( crate ) async fn unseal (
135131 self ,
136132 spec : UnsealSpec < ' _ > ,
137- cipher : & Encryption < impl Credentials < Token = ServiceToken > > ,
133+ cipher : & ZeroKmsCipher ,
138134 ) -> Result < Unsealed , SealError > {
139135 let mut vec = Self :: unseal_all ( vec ! [ self ] , spec, cipher) . await ?;
140136
@@ -207,35 +203,36 @@ impl TryFrom<SealedTableEntry> for HashMap<String, AttributeValue> {
207203
208204#[ cfg( test) ]
209205mod tests {
206+ use crate :: encrypted_table:: ZeroKmsCipher ;
207+
210208 use super :: SealedTableEntry ;
211209 use cipherstash_client:: {
212- credentials:: { auto_refresh:: AutoRefresh , service_credentials:: ServiceCredentials } ,
213- encryption:: Encryption ,
214- ConsoleConfig , ZeroKMS , ZeroKMSConfig ,
210+ credentials:: auto_refresh:: AutoRefresh , ConsoleConfig , ZeroKMS , ZeroKMSConfig ,
215211 } ;
216212 use miette:: IntoDiagnostic ;
217- use std:: borrow:: Cow ;
218-
219- type Cipher = Encryption < AutoRefresh < ServiceCredentials > > ;
213+ use std:: { borrow:: Cow , sync:: Arc } ;
220214
221215 // FIXME: Use the test cipher from CipherStash Client when that's ready
222- async fn get_cipher ( ) -> Result < Cipher , Box < dyn std:: error:: Error > > {
223- let console_config = ConsoleConfig :: builder ( ) . with_env ( ) . build ( ) ?;
216+ async fn get_cipher ( ) -> Result < Arc < ZeroKmsCipher > , Box < dyn std:: error:: Error > > {
217+ let console_config = ConsoleConfig :: builder ( )
218+ . with_env ( )
219+ . build ( )
220+ . into_diagnostic ( ) ?;
224221 let zero_kms_config = ZeroKMSConfig :: builder ( )
225222 . decryption_log ( true )
226223 . with_env ( )
227224 . console_config ( & console_config)
228- . build_with_client_key ( ) ?;
225+ . build_with_client_key ( )
226+ . into_diagnostic ( ) ?;
229227
230- let zero_kms_client = ZeroKMS :: new_with_client_key (
228+ let cipher = ZeroKMS :: new_with_client_key (
231229 & zero_kms_config. base_url ( ) ,
232230 AutoRefresh :: new ( zero_kms_config. credentials ( ) ) ,
233231 zero_kms_config. decryption_log_path ( ) . as_deref ( ) ,
234232 zero_kms_config. client_key ( ) ,
235233 ) ;
236234
237- let config = zero_kms_client. load_dataset_config ( ) . await ?;
238- Ok ( Encryption :: new ( config. index_root_key , zero_kms_client) )
235+ Ok ( Arc :: new ( cipher) )
239236 }
240237
241238 #[ tokio:: test]
@@ -248,6 +245,7 @@ mod tests {
248245 let results = SealedTableEntry :: unseal_all ( vec ! [ ] , spec, & cipher)
249246 . await
250247 . into_diagnostic ( ) ?;
248+
251249 assert ! ( results. is_empty( ) ) ;
252250
253251 Ok ( ( ) )
0 commit comments