@@ -49,7 +49,6 @@ struct RecordsWithTerms<'a> {
4949
5050impl < ' a > RecordsWithTerms < ' a > {
5151 fn new ( records : Vec < RecordWithTerms < ' a > > , num_protected_attributes : usize ) -> Self {
52- println ! ( "Creating RecordsWithTerms with {} protected attrs" , num_protected_attributes) ;
5352 Self {
5453 num_protected_attributes,
5554 records,
@@ -93,14 +92,8 @@ impl<'a> RecordsWithTerms<'a> {
9392 . collect ( )
9493
9594 } else {
96- println ! ( "Protecteds before encryption: {:?}" , protected) ;
9795 let encrypted = protected. encrypt_all ( cipher, num_records) . await ?;
9896
99- println ! ( "Encrypted len = {}" , encrypted. len( ) ) ;
100- println ! ( "Unprotected len = {}" , unprotecteds. len( ) ) ;
101- println ! ( "Encrypted: {:?}" , encrypted) ;
102- println ! ( "Unprotected: {:?}" , unprotecteds) ;
103-
10497 encrypted
10598 . into_iter ( )
10699 . zip_eq ( unprotecteds. into_iter ( ) )
@@ -235,124 +228,6 @@ impl Sealer {
235228 Self :: index_all_terms ( records, protected_attributes, cipher, term_length) ?
236229 . encrypt ( cipher)
237230 . await
238- /*let records = records.into_iter();
239- let records_len = records.size_hint().1.unwrap_or(1);
240-
241- let protected_attributes = protected_attributes.as_ref();
242-
243- let mut protected = Vec::with_capacity(records_len * protected_attributes.len());
244- let mut table_entries = Vec::with_capacity(records_len);
245-
246- for mut record in records {
247- let mut pk = record.pk;
248- let mut sk = record.sk;
249-
250- if record.is_pk_encrypted {
251- pk = b64_encode(hmac(&pk, None, cipher)?);
252- }
253-
254- if record.is_sk_encrypted {
255- sk = b64_encode(hmac(&sk, Some(pk.as_str()), cipher)?);
256- }
257-
258- let type_name = &record.type_name;
259-
260- for attr in protected_attributes.iter() {
261- protected.extend(record.unsealed.remove_protected_with_descriptor(attr)?);
262- }
263-
264- let terms: Vec<(Cow<'_, str>, IndexType, Vec<u8>)> = record
265- .unsealed_indexes
266- .into_iter()
267- .map(|(attr, index, index_name, index_type)| {
268- let term = cipher.compound_index(
269- &CompoundIndex::new(index),
270- attr,
271- Some(format!("{}#{}", type_name, index_name)),
272- term_length,
273- )?;
274-
275- Ok::<_, SealError>((index_name, index_type, term))
276- })
277- .map(|index_term| match index_term {
278- Ok((index_name, index_type, IndexTerm::Binary(x))) => {
279- Ok(vec![(index_name, index_type, x)])
280- }
281- Ok((index_name, index_type, IndexTerm::BinaryVec(x))) => Ok(x
282- .into_iter()
283- .take(MAX_TERMS_PER_INDEX)
284- .map(|x| (index_name.clone(), index_type, x))
285- .collect()),
286- _ => Err(SealError::InvalidCiphertext("Invalid index term".into())),
287- })
288- .flatten_ok()
289- .try_collect()?;
290-
291- table_entries.push((
292- PrimaryKeyParts { pk, sk },
293- record.unsealed.unprotected().clone(),
294- terms,
295- ));
296- }
297-
298- // Only encrypt if there are actually protected attributes
299- if !protected_attributes.is_empty() {
300- let encrypted = cipher
301- .encrypt(protected.iter().map(|(a, b)| (a, b.as_str())))
302- .await?;
303-
304- for (encrypted, (_, attributes, _)) in encrypted
305- .chunks_exact(protected.len())
306- .zip(table_entries.iter_mut())
307- {
308- for (enc, name) in encrypted.iter().zip(protected.iter()) {
309- let name: &str = name.1.deref();
310-
311- println!("Inserting protected attribute: {}", name);
312-
313- attributes.insert(
314- String::from(match name {
315- // TODO: Possibly reinstate or move this
316- //"pk" => "__pk",
317- //"sk" => "__sk",
318- _ => name,
319- }),
320- TableAttribute::Bytes(enc.to_vec().map_err(|_| {
321- SealError::InvalidCiphertext(
322- "Failed to serialize encrypted record as bytes".into(),
323- )
324- })?),
325- );
326- }
327- }
328- }
329-
330- let mut output = Vec::with_capacity(table_entries.len());
331-
332- for (PrimaryKeyParts { pk, sk }, attributes, terms) in table_entries.into_iter() {
333- let terms = terms
334- .into_iter()
335- .enumerate()
336- .map(|(i, (index_name, index_type, term))| {
337- let sk = b64_encode(hmac(
338- &format_term_key(sk.as_str(), &index_name, index_type, i),
339- Some(pk.as_str()),
340- cipher,
341- )?);
342-
343- Ok::<_, SealError>(Term { sk, value: term })
344- })
345- .collect::<Result<_, SealError>>()?;
346-
347- output.push(dbg!(Sealed {
348- pk,
349- sk,
350- attributes,
351- terms,
352- }));
353- }
354-
355- Ok(output)*/
356231 }
357232
358233 pub ( crate ) async fn seal < ' a > (
@@ -411,7 +286,6 @@ impl Sealed {
411286 self ,
412287 mut index_predicate : impl FnMut ( & str , & TableAttribute ) -> bool ,
413288 ) -> ( SealedTableEntry , Vec < SealedTableEntry > ) {
414- // TODO: Is this normalization necessary? - try removing it
415289 let root_attributes = self . attributes ;
416290
417291 let index_attributes: TableAttributes = root_attributes
0 commit comments