decrypt_all check is the value is clear or a commitment

This commit is contained in:
Sosthene 2024-12-06 15:26:07 +01:00 committed by Nicolas Cantu
parent 6fbc3f6f4a
commit eef48ce834

View File

@ -236,16 +236,17 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> {
.map_err(|_| Error::msg(format!("Failed to decrypt field {}", field)))?;
let decrypted_value: String = String::from_utf8(plain)?;
fields2plain.insert(field.to_owned(), Value::String(decrypted_value));
fields2plain.insert(field.to_owned(), serde_json::from_str(&decrypted_value)?);
} else if let Some(commitment) = fields2commit.get(field) { // We should always have a commitment
// We check if the hashed value is the commitment
let hashed_value = AnkPcdHash::from_value_with_outpoint(encrypted_value, &serialize(&commited_in));
if commitment.as_str().unwrap() != &hashed_value.to_string() {
// The value is encrypted, and we don't have the key
// We put the commitment instead of the encrypted value
fields2plain.insert(field.to_owned(), commitment.clone());
} // else it means the value is simply unencrypted, we leave it as it is
} else {
// 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)))
}
return Err(Error::msg(format!("Missing commitment for field {}", field)));
}
}