Skip to content

Commit

Permalink
In case decryption fails, do not error out
Browse files Browse the repository at this point in the history
  • Loading branch information
richajaindce committed Sep 10, 2024
1 parent f199c46 commit 1caf7d5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ipa-core/src/cli/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
iter::zip,
path::PathBuf,
};

use crate::report::InvalidReportError;
use clap::Parser;
use rand::thread_rng;

Expand Down Expand Up @@ -146,16 +146,16 @@ impl DecryptedReports {
}

impl Iterator for DecryptedReports {
type Item = OprfReport<BA8, BA3, BA20>;
type Item = Result<OprfReport<BA8, BA3, BA20>, InvalidReportError>;

fn next(&mut self) -> Option<Self::Item> {
let mut line = String::new();
if self.reader.read_line(&mut line).unwrap() > 0 {
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<BA8, BA3, BA20> =
enc_report.decrypt(&self.key_registry).unwrap();
let dec_report =
enc_report.decrypt(&self.key_registry);
Some(dec_report)
} else {
None
Expand All @@ -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,
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 1caf7d5

Please sign in to comment.