decrypt_all check is the value is clear or a commitment
This commit is contained in:
parent
adeb5e6537
commit
348e509ddc
19
src/pcd.rs
19
src/pcd.rs
@ -236,16 +236,17 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> {
|
|||||||
.map_err(|_| Error::msg(format!("Failed to decrypt field {}", field)))?;
|
.map_err(|_| Error::msg(format!("Failed to decrypt field {}", field)))?;
|
||||||
let decrypted_value: String = String::from_utf8(plain)?;
|
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 {
|
} else {
|
||||||
// We put the commitment instead of the encrypted value
|
return Err(Error::msg(format!("Missing commitment for field {}", field)));
|
||||||
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)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user