events: Correct properties of SecretStorageV1AesHmacSha2Properties

The `key` and `iv` properties of this type are, and have always been, optional according to the spec.
This commit is contained in:
Richard van der Hoff 2024-01-18 13:54:39 +00:00 committed by GitHub
parent aa3acd88d2
commit 9d81576af7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 19 deletions

View File

@ -2,6 +2,7 @@
Breaking changes:
- The properties of `SecretStorageV1AesHmacSha2Properties` are now `Option`al.
- Remove `event_id` methods from relation types
- The required power level is different whether the user wants to redact their
own event or an event from another user:

View File

@ -54,6 +54,10 @@ fn is_default_bits(val: &UInt) -> bool {
}
/// A key description encrypted using a specified algorithm.
///
/// The only algorithm currently specified is `m.secret_storage.v1.aes-hmac-sha2`, so this
/// essentially represents `AesHmacSha2KeyDescription` in the
/// [spec](https://spec.matrix.org/v1.9/client-server-api/#msecret_storagev1aes-hmac-sha2).
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[derive(Clone, Debug, Serialize, EventContent)]
#[ruma_event(type = "m.secret_storage.key.*", kind = GlobalAccountData)]
@ -131,20 +135,23 @@ impl SecretStorageEncryptionAlgorithm {
}
/// The key properties for the `m.secret_storage.v1.aes-hmac-sha2` algorithm.
///
/// Corresponds to the AES-specific properties of `AesHmacSha2KeyDescription` in the
/// [spec](https://spec.matrix.org/v1.9/client-server-api/#msecret_storagev1aes-hmac-sha2).
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SecretStorageV1AesHmacSha2Properties {
/// The 16-byte initialization vector, encoded as base64.
pub iv: Base64,
pub iv: Option<Base64>,
/// The MAC, encoded as base64.
pub mac: Base64,
pub mac: Option<Base64>,
}
impl SecretStorageV1AesHmacSha2Properties {
/// Creates a new `SecretStorageV1AesHmacSha2Properties` with the given initialization vector
/// and MAC.
pub fn new(iv: Base64, mac: Base64) -> Self {
/// Creates a new `SecretStorageV1AesHmacSha2Properties` with the given
/// initialization vector and MAC.
pub fn new(iv: Option<Base64>, mac: Option<Base64>) -> Self {
Self { iv, mac }
}
}
@ -182,8 +189,8 @@ mod tests {
let mut content = SecretStorageKeyEventContent::new(
"my_key".into(),
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv: Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap(),
mac: Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap(),
iv: Some(Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap()),
mac: Some(Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap()),
}),
);
content.name = Some("my_key".to_owned());
@ -216,10 +223,11 @@ mod tests {
assert_matches!(
content.algorithm,
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv,
mac
iv: Some(iv),
mac: Some(mac)
})
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
}
@ -241,8 +249,8 @@ mod tests {
assert_matches!(
content.algorithm,
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv,
mac
iv: Some(iv),
mac: Some(mac)
})
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
@ -257,8 +265,8 @@ mod tests {
"my_key".into(),
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(
SecretStorageV1AesHmacSha2Properties {
iv: Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap(),
mac: Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap(),
iv: Some(Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap()),
mac: Some(Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap()),
},
),
)
@ -309,8 +317,8 @@ mod tests {
assert_matches!(
content.algorithm,
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv,
mac
iv: Some(iv),
mac: Some(mac)
})
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
@ -322,8 +330,8 @@ mod tests {
let mut content = SecretStorageKeyEventContent::new(
"my_key_id".into(),
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv: Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap(),
mac: Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap(),
iv: Some(Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap()),
mac: Some(Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap()),
}),
);
content.name = Some("my_key".to_owned());
@ -359,8 +367,8 @@ mod tests {
assert_matches!(
ev.content.algorithm,
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
iv,
mac
iv: Some(iv),
mac: Some(mac)
})
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");