@@ -23,7 +23,7 @@ use cipherstash_client::{
2323 } ,
2424 credentials:: { auto_refresh:: AutoRefresh , service_credentials:: ServiceCredentials } ,
2525 encryption:: ScopedCipher ,
26- zerokms:: { ZeroKMS , ZeroKMSWithClientKey } ,
26+ zerokms:: { ClientKey , ZeroKMS , ZeroKMSWithClientKey } ,
2727} ;
2828use log:: info;
2929use std:: {
@@ -67,8 +67,6 @@ impl<D> EncryptedTable<D> {
6767
6868impl EncryptedTable < Headless > {
6969 pub async fn init_headless ( ) -> Result < Self , InitError > {
70- info ! ( "Initializing..." ) ;
71-
7270 let console_config = ConsoleConfig :: builder ( ) . with_env ( ) . build ( ) ?;
7371
7472 let cts_config = CtsConfig :: builder ( ) . with_env ( ) . build ( ) ?;
@@ -80,6 +78,14 @@ impl EncryptedTable<Headless> {
8078 . cts_config ( & cts_config)
8179 . build_with_client_key ( ) ?;
8280
81+ Self :: init_headless_with_zerokms_config ( zerokms_config) . await
82+ }
83+
84+ pub async fn init_headless_with_zerokms_config (
85+ zerokms_config : ZeroKMSConfig < ClientKey > ,
86+ ) -> Result < Self , InitError > {
87+ info ! ( "Initializing..." ) ;
88+
8389 let cipher = ZeroKMS :: new_with_client_key (
8490 & zerokms_config. base_url ( ) ,
8591 AutoRefresh :: new ( zerokms_config. credentials ( ) ) ,
@@ -413,6 +419,22 @@ impl EncryptedTable<Dynamo> {
413419 } )
414420 }
415421
422+ pub async fn init_with_zerokms_config (
423+ zerokms_config : ZeroKMSConfig < ClientKey > ,
424+ db : aws_sdk_dynamodb:: Client ,
425+ table_name : impl Into < String > ,
426+ ) -> Result < Self , InitError > {
427+ let table = EncryptedTable :: init_headless_with_zerokms_config ( zerokms_config) . await ?;
428+
429+ Ok ( Self {
430+ db : Dynamo {
431+ table_name : table_name. into ( ) ,
432+ db,
433+ } ,
434+ cipher : table. cipher ,
435+ } )
436+ }
437+
416438 /// Get a record from the table by primary key from the default dataset.
417439 pub async fn get < T > ( & self , k : impl Into < T :: PrimaryKey > ) -> Result < Option < T > , GetError >
418440 where
0 commit comments