Make Pcd::decrypt_fields() replace encrypted by commitments

This commit is contained in:
Sosthene 2024-11-29 09:09:54 +01:00
parent 64908496eb
commit b38189beca

View File

@ -185,6 +185,7 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> {
fn decrypt_fields(
&self,
fields2commit: &Map<String, Value>,
fields2keys: &Map<String, Value>,
fields2plain: &mut Map<String, Value>,
) -> 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)))
}
}
}