diff --git a/ipa-core/src/cli/crypto.rs b/ipa-core/src/cli/crypto.rs index 69acd1e11..4fa4d9a9a 100644 --- a/ipa-core/src/cli/crypto.rs +++ b/ipa-core/src/cli/crypto.rs @@ -5,7 +5,7 @@ use std::{ iter::zip, path::PathBuf, }; - +use crate::report::InvalidReportError; use clap::Parser; use rand::thread_rng; @@ -146,7 +146,7 @@ impl DecryptedReports { } impl Iterator for DecryptedReports { - type Item = OprfReport; + type Item = Result, InvalidReportError>; fn next(&mut self) -> Option { let mut line = String::new(); @@ -154,8 +154,8 @@ impl Iterator for DecryptedReports { let encrypted_report_bytes = hex::decode(line.trim()).unwrap(); let enc_report = EncryptedOprfReport::from_bytes(encrypted_report_bytes.as_slice()).unwrap(); - let dec_report: OprfReport = - enc_report.decrypt(&self.key_registry).unwrap(); + let dec_report = + enc_report.decrypt(&self.key_registry); Some(dec_report) } else { None @@ -182,10 +182,12 @@ pub async fn decrypt_and_reconstruct(args: DecryptArgs) -> Result<(), BoxError> .open(args.output_file)?, ); - for (dec_report1, (dec_report2, dec_report3)) in - decrypted_reports1.zip(decrypted_reports2.zip(decrypted_reports3)) + for (idx, (dec_report1, (dec_report2, dec_report3))) in + decrypted_reports1.zip(decrypted_reports2.zip(decrypted_reports3)).enumerate() { - let timestamp = [ + match (dec_report1, dec_report2, dec_report3) { + (Ok(dec_report1), Ok(dec_report2), Ok(dec_report3)) => { + let timestamp = [ dec_report1.timestamp, dec_report2.timestamp, dec_report3.timestamp, @@ -233,6 +235,10 @@ pub async fn decrypt_and_reconstruct(args: DecryptArgs) -> Result<(), BoxError> breakdown_key, trigger_value, )?; + } + _ => println!("Decryption failed for record no {idx}") + } + } Ok(())