crypto: Remove some duplicated types after the group session split.

master
Damir Jelić 2020-09-09 11:51:00 +02:00
parent acfd0cdb07
commit 98f69aed41
1 changed files with 3 additions and 49 deletions

View File

@ -12,14 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::{convert::TryInto, fmt, sync::Arc, time::Duration}; use std::{collections::BTreeMap, convert::TryInto, fmt, sync::Arc};
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{ events::{room::encrypted::EncryptedEventContent, AnySyncRoomEvent, SyncMessageEvent},
room::{encrypted::EncryptedEventContent, encryption::EncryptionEventContent}, identifiers::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId},
AnySyncRoomEvent, SyncMessageEvent,
},
identifiers::{EventEncryptionAlgorithm, RoomId},
locks::Mutex, locks::Mutex,
Raw, Raw,
}; };
@ -38,49 +35,6 @@ pub use olm_rs::{
use super::GroupSessionKey; use super::GroupSessionKey;
use crate::error::{EventError, MegolmResult}; use crate::error::{EventError, MegolmResult};
const ROTATION_PERIOD: Duration = Duration::from_millis(604800000);
const ROTATION_MESSAGES: u64 = 100;
/// Settings for an encrypted room.
///
/// This determines the algorithm and rotation periods of a group session.
#[derive(Debug)]
pub struct EncryptionSettings {
/// The encryption algorithm that should be used in the room.
pub algorithm: EventEncryptionAlgorithm,
/// How long the session should be used before changing it.
pub rotation_period: Duration,
/// How many messages should be sent before changing the session.
pub rotation_period_msgs: u64,
}
impl Default for EncryptionSettings {
fn default() -> Self {
Self {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
rotation_period: ROTATION_PERIOD,
rotation_period_msgs: ROTATION_MESSAGES,
}
}
}
impl From<&EncryptionEventContent> for EncryptionSettings {
fn from(content: &EncryptionEventContent) -> Self {
let rotation_period: Duration = content
.rotation_period_ms
.map_or(ROTATION_PERIOD, |r| Duration::from_millis(r.into()));
let rotation_period_msgs: u64 = content
.rotation_period_msgs
.map_or(ROTATION_MESSAGES, Into::into);
Self {
algorithm: content.algorithm.clone(),
rotation_period,
rotation_period_msgs,
}
}
}
/// Inbound group session. /// Inbound group session.
/// ///
/// Inbound group sessions are used to exchange room messages between a group of /// Inbound group sessions are used to exchange room messages between a group of