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))) + } } }