Simplify MegolmV1AesSha2Content construction

This commit is contained in:
Jonas Platte 2020-07-24 20:25:04 +02:00
parent e04ed242fc
commit 26850dbafb
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -67,6 +67,9 @@ impl CiphertextInfo {
}
/// The payload for `EncryptedEvent` using the *m.megolm.v1.aes-sha2* algorithm.
///
/// To createn an instance of this type, first create a `MegolmV1AesSh2ContentInit` and convert it
/// via `MegolmV1AesSha2Content::from` / `.into()`.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MegolmV1AesSha2Content {
@ -83,14 +86,6 @@ pub struct MegolmV1AesSha2Content {
pub session_id: String,
}
impl MegolmV1AesSha2Content {
/// Creates a new `MegolmV1AesSha2Content` from the given init struct.
pub fn new(init: MegolmV1AesSha2ContentInit) -> Self {
let MegolmV1AesSha2ContentInit { ciphertext, sender_key, device_id, session_id } = init;
Self { ciphertext, sender_key, device_id, session_id }
}
}
/// Mandatory initial set of fields of `MegolmV1AesSha2Content`.
///
/// This struct will not be updated even if additional fields are added to `MegolmV1AesSha2Content`
@ -110,6 +105,14 @@ pub struct MegolmV1AesSha2ContentInit {
pub session_id: String,
}
impl From<MegolmV1AesSha2ContentInit> for MegolmV1AesSha2Content {
/// Creates a new `MegolmV1AesSha2Content` from the given init struct.
fn from(init: MegolmV1AesSha2ContentInit) -> Self {
let MegolmV1AesSha2ContentInit { ciphertext, sender_key, device_id, session_id } = init;
Self { ciphertext, sender_key, device_id, session_id }
}
}
#[cfg(test)]
mod tests {
use matches::assert_matches;