@@ -8,8 +8,8 @@ pub use self::{
88use crate :: {
99 crypto:: * ,
1010 errors:: * ,
11- traits:: { Decryptable , PrimaryKeyParts , Searchable } ,
12- Identifiable , IndexType , PrimaryKey ,
11+ traits:: { Decryptable , Preparable , PrimaryKeyParts , Searchable } ,
12+ Identifiable , IndexType ,
1313} ;
1414use aws_sdk_dynamodb:: types:: { AttributeValue , Delete , Put , TransactWriteItem } ;
1515use cipherstash_client:: {
@@ -103,6 +103,20 @@ pub struct PreparedRecord {
103103 sealer : Sealer ,
104104}
105105
106+ impl PreparedRecord {
107+ pub ( crate ) fn new (
108+ protected_indexes : Cow < ' static , [ ( Cow < ' static , str > , IndexType ) ] > ,
109+ protected_attributes : Cow < ' static , [ Cow < ' static , str > ] > ,
110+ sealer : Sealer ,
111+ ) -> Self {
112+ Self {
113+ protected_indexes,
114+ protected_attributes,
115+ sealer,
116+ }
117+ }
118+ }
119+
106120impl DynamoRecordPatch {
107121 /// Consume the [`DynamoRecordPatch`] and create a list of [`TransactWriteItem`] used to put
108122 /// and delete records from DynamoDB.
@@ -224,55 +238,6 @@ impl<D> EncryptedTable<D> {
224238 } )
225239 }
226240
227- pub fn prepare_record < E : Searchable + Identifiable > (
228- & self ,
229- record : E ,
230- ) -> Result < PreparedRecord , SealError > {
231- let type_name = E :: type_name ( ) ;
232-
233- let PrimaryKeyParts { pk, sk } = record
234- . get_primary_key ( )
235- . into_parts ( & type_name, E :: sort_key_prefix ( ) . as_deref ( ) ) ;
236-
237- let protected_indexes = E :: protected_indexes ( ) ;
238- let protected_attributes = E :: protected_attributes ( ) ;
239-
240- let unsealed_indexes = protected_indexes
241- . iter ( )
242- . map ( |( index_name, index_type) | {
243- record
244- . attribute_for_index ( index_name, * index_type)
245- . and_then ( |attr| {
246- E :: index_by_name ( index_name, * index_type)
247- . map ( |index| ( attr, index, index_name. clone ( ) , * index_type) )
248- } )
249- . ok_or ( SealError :: MissingAttribute ( index_name. to_string ( ) ) )
250- } )
251- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
252-
253- let unsealed = record. into_unsealed ( ) ;
254-
255- let sealer = Sealer {
256- pk,
257- sk,
258-
259- is_sk_encrypted : E :: is_sk_encrypted ( ) ,
260- is_pk_encrypted : E :: is_pk_encrypted ( ) ,
261-
262- type_name,
263-
264- unsealed_indexes,
265-
266- unsealed,
267- } ;
268-
269- Ok ( PreparedRecord {
270- protected_indexes,
271- protected_attributes,
272- sealer,
273- } )
274- }
275-
276241 /// Create a [`DynamoRecordPatch`] used to insert records into DynamoDB.
277242 ///
278243 /// This will create a root record with all attributes and index records that only include
@@ -401,7 +366,7 @@ impl EncryptedTable<Dynamo> {
401366 where
402367 T : Searchable + Identifiable ,
403368 {
404- let record = self . prepare_record ( record ) ?;
369+ let record = record . prepare_record ( ) ?;
405370
406371 let transact_items = self
407372 . create_put_patch (
0 commit comments