From b38189beca6994e598ad7ed29d495c14e5662e77 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Fri, 29 Nov 2024 09:09:54 +0100 Subject: [PATCH] Make Pcd::decrypt_fields() replace encrypted by commitments --- src/pcd.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pcd.rs b/src/pcd.rs index a2690d7..4bde4a1 100644 --- a/src/pcd.rs +++ b/src/pcd.rs @@ -185,6 +185,7 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> { fn decrypt_fields( &self, + fields2commit: &Map, fields2keys: &Map, fields2plain: &mut Map, ) -> Result<()> { @@ -222,8 +223,14 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> { fields2plain.insert(field.to_owned(), Value::String(decrypted_value)); } else { - // We keep the original value, that allows us to have fields that are always left unencrypted - fields2plain.insert(field.to_owned(), encrypted_value.clone()); + // We put the commitment instead of the encrypted value + let commitment = fields2commit.get(field); + match commitment { + Some(hash) => { + fields2plain.insert(field.to_owned(), hash.clone()); + }, + None => return Err(Error::msg(format!("Missing commitment for field {}", field))) + } } }