@@ -105,17 +105,25 @@ where
105
105
{
106
106
let protected_attributes = target. protected_attributes ( ) ;
107
107
108
- // TODO: Maybe use a wrapper type?
109
- let mut attributes: HashMap < String , String > = Default :: default ( ) ;
110
- for ( name, plaintext) in protected_attributes. iter ( ) {
111
- // TODO: Use the bulk encrypt
112
- if let Some ( ct) = cipher
113
- . encrypt_single ( & plaintext, & format ! ( "{}#{}" , E :: type_name( ) , name) )
114
- . await ?
115
- {
116
- attributes. insert ( name. to_string ( ) , ct) ;
117
- }
118
- }
108
+ let entries_to_encrypt = protected_attributes
109
+ . into_iter ( )
110
+ . map ( |( name, plaintext) | ( name, plaintext, format ! ( "{}#{}" , E :: type_name( ) , name) ) )
111
+ . collect :: < Vec < _ > > ( ) ;
112
+
113
+ let encrypted = cipher
114
+ . encrypt (
115
+ entries_to_encrypt
116
+ . iter ( )
117
+ . map ( |( _, plaintext, descriptor) | ( plaintext, descriptor. as_str ( ) ) ) ,
118
+ )
119
+ . await ?;
120
+
121
+ let attributes: HashMap < String , String > = entries_to_encrypt
122
+ . into_iter ( )
123
+ . map ( |( name, _, _) | name)
124
+ . zip ( encrypted. into_iter ( ) )
125
+ . flat_map ( |( name, ct) | ct. map ( |ct| ( name. to_string ( ) , ct) ) )
126
+ . collect ( ) ;
119
127
120
128
let partition_key = encrypt_partition_key ( & target. partition_key ( ) , cipher) ?;
121
129
0 commit comments