Update redact to take ownership of the event to be redacted

This commit is contained in:
Jonas Platte 2022-12-19 10:42:27 +01:00
parent fc0b29068f
commit ba9634f5bf
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
2 changed files with 6 additions and 7 deletions

View File

@ -138,12 +138,11 @@ pub fn to_canonical_value<T: Serialize>(
/// * `object` contains a field called `signatures` that is not a JSON object. /// * `object` contains a field called `signatures` that is not a JSON object.
/// * `object` is missing the `type` field or the field is not a JSON string. /// * `object` is missing the `type` field or the field is not a JSON string.
pub fn redact( pub fn redact(
object: &CanonicalJsonObject, mut object: CanonicalJsonObject,
version: &RoomVersionId, version: &RoomVersionId,
) -> Result<CanonicalJsonObject, RedactionError> { ) -> Result<CanonicalJsonObject, RedactionError> {
let mut val = object.clone(); redact_in_place(&mut object, version)?;
redact_in_place(&mut val, version)?; Ok(object)
Ok(val)
} }
/// Redacts an event using the rules specified in the Matrix client-server specification. /// Redacts an event using the rules specified in the Matrix client-server specification.

View File

@ -321,7 +321,7 @@ pub fn reference_hash(
value: &CanonicalJsonObject, value: &CanonicalJsonObject,
version: &RoomVersionId, version: &RoomVersionId,
) -> Result<String, Error> { ) -> Result<String, Error> {
let redacted_value = redact(value, version)?; let redacted_value = redact(value.clone(), version)?;
let json = let json =
canonical_json_with_fields_to_remove(&redacted_value, REFERENCE_HASH_FIELDS_TO_REMOVE)?; canonical_json_with_fields_to_remove(&redacted_value, REFERENCE_HASH_FIELDS_TO_REMOVE)?;
@ -458,7 +458,7 @@ where
_ => return Err(JsonError::not_of_type("hashes", JsonType::Object)), _ => return Err(JsonError::not_of_type("hashes", JsonType::Object)),
}; };
let mut redacted = redact(object, version)?; let mut redacted = redact(object.clone(), version)?;
sign_json(entity_id, key_pair, &mut redacted)?; sign_json(entity_id, key_pair, &mut redacted)?;
@ -539,7 +539,7 @@ pub fn verify_event(
object: &CanonicalJsonObject, object: &CanonicalJsonObject,
version: &RoomVersionId, version: &RoomVersionId,
) -> Result<Verified, Error> { ) -> Result<Verified, Error> {
let redacted = redact(object, version)?; let redacted = redact(object.clone(), version)?;
let hash = match object.get("hashes") { let hash = match object.get("hashes") {
Some(hashes_value) => match hashes_value { Some(hashes_value) => match hashes_value {