crypto: Remove the sas event enums module
parent
ac04b0c36e
commit
bd5dda370d
|
@ -39,7 +39,7 @@ use matrix_sdk_common::{
|
||||||
CanonicalJsonValue,
|
CanonicalJsonValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{sas::OutgoingContent, FlowId};
|
use super::FlowId;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AnyEvent<'a> {
|
pub enum AnyEvent<'a> {
|
||||||
|
@ -709,3 +709,127 @@ impl OwnedAcceptContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum OutgoingContent {
|
||||||
|
Room(RoomId, AnyMessageEventContent),
|
||||||
|
ToDevice(AnyToDeviceEventContent),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<OwnedStartContent> for OutgoingContent {
|
||||||
|
fn from(content: OwnedStartContent) -> Self {
|
||||||
|
match content {
|
||||||
|
OwnedStartContent::Room(r, c) => {
|
||||||
|
(r, AnyMessageEventContent::KeyVerificationStart(c)).into()
|
||||||
|
}
|
||||||
|
OwnedStartContent::ToDevice(c) => {
|
||||||
|
AnyToDeviceEventContent::KeyVerificationStart(c).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AnyToDeviceEventContent> for OutgoingContent {
|
||||||
|
fn from(content: AnyToDeviceEventContent) -> Self {
|
||||||
|
OutgoingContent::ToDevice(content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(RoomId, AnyMessageEventContent)> for OutgoingContent {
|
||||||
|
fn from(content: (RoomId, AnyMessageEventContent)) -> Self {
|
||||||
|
OutgoingContent::Room(content.0, content.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use crate::{OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl From<OutgoingVerificationRequest> for OutgoingContent {
|
||||||
|
fn from(request: OutgoingVerificationRequest) -> Self {
|
||||||
|
match request {
|
||||||
|
OutgoingVerificationRequest::ToDevice(r) => Self::try_from(r).unwrap(),
|
||||||
|
OutgoingVerificationRequest::InRoom(r) => Self::from(r),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl From<RoomMessageRequest> for OutgoingContent {
|
||||||
|
fn from(value: RoomMessageRequest) -> Self {
|
||||||
|
(value.room_id, value.content).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl TryFrom<ToDeviceRequest> for OutgoingContent {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(value: ToDeviceRequest) -> Result<Self, Self::Error> {
|
||||||
|
use matrix_sdk_common::events::EventType;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
let json: Value = serde_json::from_str(
|
||||||
|
value
|
||||||
|
.messages
|
||||||
|
.values()
|
||||||
|
.next()
|
||||||
|
.and_then(|m| m.values().next().map(|j| j.get()))
|
||||||
|
.ok_or(())?,
|
||||||
|
)
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
match value.event_type {
|
||||||
|
EventType::KeyVerificationRequest => {
|
||||||
|
Ok(AnyToDeviceEventContent::KeyVerificationRequest(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
EventType::KeyVerificationReady => Ok(AnyToDeviceEventContent::KeyVerificationReady(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationDone => Ok(AnyToDeviceEventContent::KeyVerificationDone(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationStart => Ok(AnyToDeviceEventContent::KeyVerificationStart(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationKey => Ok(AnyToDeviceEventContent::KeyVerificationKey(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationAccept => Ok(AnyToDeviceEventContent::KeyVerificationAccept(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationMac => Ok(AnyToDeviceEventContent::KeyVerificationMac(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
EventType::KeyVerificationCancel => Ok(AnyToDeviceEventContent::KeyVerificationCancel(
|
||||||
|
serde_json::from_value(json).map_err(|_| ())?,
|
||||||
|
)
|
||||||
|
.into()),
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl TryFrom<OutgoingRequest> for OutgoingContent {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(value: OutgoingRequest) -> Result<Self, ()> {
|
||||||
|
match value.request() {
|
||||||
|
crate::OutgoingRequests::KeysUpload(_) => Err(()),
|
||||||
|
crate::OutgoingRequests::KeysQuery(_) => Err(()),
|
||||||
|
crate::OutgoingRequests::ToDeviceRequest(r) => Self::try_from(r.clone()),
|
||||||
|
crate::OutgoingRequests::SignatureUpload(_) => Err(()),
|
||||||
|
crate::OutgoingRequests::RoomMessage(r) => Ok(Self::from(r.clone())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ use std::{convert::TryFrom, sync::Arc};
|
||||||
|
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
identifiers::{DeviceId, EventId, UserId},
|
identifiers::{DeviceId, UserId},
|
||||||
locks::Mutex,
|
locks::Mutex,
|
||||||
uuid::Uuid,
|
uuid::Uuid,
|
||||||
};
|
};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
event_enums::{AnyEvent, AnyVerificationContent},
|
event_enums::{AnyEvent, AnyVerificationContent, OutgoingContent},
|
||||||
requests::VerificationRequest,
|
requests::VerificationRequest,
|
||||||
sas::{content_to_request, OutgoingContent, Sas},
|
sas::{content_to_request, Sas},
|
||||||
FlowId, Verification, VerificationResult,
|
FlowId, Verification, VerificationResult,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -398,8 +398,7 @@ mod test {
|
||||||
olm::PrivateCrossSigningIdentity,
|
olm::PrivateCrossSigningIdentity,
|
||||||
store::{CryptoStore, MemoryStore},
|
store::{CryptoStore, MemoryStore},
|
||||||
verification::{
|
verification::{
|
||||||
event_enums::{AcceptContent, KeyContent, MacContent},
|
event_enums::{AcceptContent, KeyContent, MacContent, OutgoingContent},
|
||||||
sas::OutgoingContent,
|
|
||||||
test::wrap_any_to_device_content,
|
test::wrap_any_to_device_content,
|
||||||
},
|
},
|
||||||
ReadOnlyAccount, ReadOnlyDevice,
|
ReadOnlyAccount, ReadOnlyDevice,
|
||||||
|
|
|
@ -19,6 +19,7 @@ mod sas;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use event_enums::OutgoingContent;
|
||||||
pub use machine::{VerificationCache, VerificationMachine};
|
pub use machine::{VerificationCache, VerificationMachine};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::keys::upload_signatures::Request as SignatureUploadRequest,
|
api::r0::keys::upload_signatures::Request as SignatureUploadRequest,
|
||||||
|
@ -36,7 +37,6 @@ pub use requests::VerificationRequest;
|
||||||
pub use sas::{AcceptSettings, Sas};
|
pub use sas::{AcceptSettings, Sas};
|
||||||
use tracing::{error, info, trace, warn};
|
use tracing::{error, info, trace, warn};
|
||||||
|
|
||||||
use self::sas::OutgoingContent;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::SignatureError,
|
error::SignatureError,
|
||||||
olm::PrivateCrossSigningIdentity,
|
olm::PrivateCrossSigningIdentity,
|
||||||
|
@ -450,7 +450,7 @@ pub(crate) mod test {
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::sas::OutgoingContent;
|
use super::event_enums::OutgoingContent;
|
||||||
use crate::{
|
use crate::{
|
||||||
requests::{OutgoingRequest, OutgoingRequests},
|
requests::{OutgoingRequest, OutgoingRequests},
|
||||||
OutgoingVerificationRequest,
|
OutgoingVerificationRequest,
|
||||||
|
|
|
@ -35,8 +35,8 @@ use matrix_sdk_common::{
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
event_enums::{ReadyContent, RequestContent, StartContent},
|
event_enums::{OutgoingContent, ReadyContent, RequestContent, StartContent},
|
||||||
sas::{content_to_request, OutgoingContent},
|
sas::content_to_request,
|
||||||
FlowId, VerificationCache,
|
FlowId, VerificationCache,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -599,8 +599,7 @@ mod test {
|
||||||
olm::{PrivateCrossSigningIdentity, ReadOnlyAccount},
|
olm::{PrivateCrossSigningIdentity, ReadOnlyAccount},
|
||||||
store::{Changes, CryptoStore, MemoryStore},
|
store::{Changes, CryptoStore, MemoryStore},
|
||||||
verification::{
|
verification::{
|
||||||
event_enums::{ReadyContent, StartContent},
|
event_enums::{OutgoingContent, ReadyContent, StartContent},
|
||||||
sas::OutgoingContent,
|
|
||||||
FlowId, VerificationCache,
|
FlowId, VerificationCache,
|
||||||
},
|
},
|
||||||
ReadOnlyDevice,
|
ReadOnlyDevice,
|
||||||
|
|
|
@ -1,146 +0,0 @@
|
||||||
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
|
||||||
events::{AnyMessageEventContent, AnyToDeviceEventContent},
|
|
||||||
identifiers::RoomId,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub enum OutgoingContent {
|
|
||||||
Room(RoomId, AnyMessageEventContent),
|
|
||||||
ToDevice(AnyToDeviceEventContent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<OwnedStartContent> for OutgoingContent {
|
|
||||||
fn from(content: OwnedStartContent) -> Self {
|
|
||||||
match content {
|
|
||||||
OwnedStartContent::Room(r, c) => {
|
|
||||||
(r, AnyMessageEventContent::KeyVerificationStart(c)).into()
|
|
||||||
}
|
|
||||||
OwnedStartContent::ToDevice(c) => {
|
|
||||||
AnyToDeviceEventContent::KeyVerificationStart(c).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AnyToDeviceEventContent> for OutgoingContent {
|
|
||||||
fn from(content: AnyToDeviceEventContent) -> Self {
|
|
||||||
OutgoingContent::ToDevice(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<(RoomId, AnyMessageEventContent)> for OutgoingContent {
|
|
||||||
fn from(content: (RoomId, AnyMessageEventContent)) -> Self {
|
|
||||||
OutgoingContent::Room(content.0, content.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
use crate::verification::event_enums::OwnedStartContent;
|
|
||||||
#[cfg(test)]
|
|
||||||
use crate::{OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest};
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl From<OutgoingVerificationRequest> for OutgoingContent {
|
|
||||||
fn from(request: OutgoingVerificationRequest) -> Self {
|
|
||||||
match request {
|
|
||||||
OutgoingVerificationRequest::ToDevice(r) => Self::try_from(r).unwrap(),
|
|
||||||
OutgoingVerificationRequest::InRoom(r) => Self::from(r),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl From<RoomMessageRequest> for OutgoingContent {
|
|
||||||
fn from(value: RoomMessageRequest) -> Self {
|
|
||||||
(value.room_id, value.content).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl TryFrom<ToDeviceRequest> for OutgoingContent {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(value: ToDeviceRequest) -> Result<Self, Self::Error> {
|
|
||||||
use matrix_sdk_common::events::EventType;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
let json: Value = serde_json::from_str(
|
|
||||||
value
|
|
||||||
.messages
|
|
||||||
.values()
|
|
||||||
.next()
|
|
||||||
.and_then(|m| m.values().next().map(|j| j.get()))
|
|
||||||
.ok_or(())?,
|
|
||||||
)
|
|
||||||
.map_err(|_| ())?;
|
|
||||||
|
|
||||||
match value.event_type {
|
|
||||||
EventType::KeyVerificationRequest => {
|
|
||||||
Ok(AnyToDeviceEventContent::KeyVerificationRequest(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into())
|
|
||||||
}
|
|
||||||
EventType::KeyVerificationReady => Ok(AnyToDeviceEventContent::KeyVerificationReady(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationDone => Ok(AnyToDeviceEventContent::KeyVerificationDone(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationStart => Ok(AnyToDeviceEventContent::KeyVerificationStart(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationKey => Ok(AnyToDeviceEventContent::KeyVerificationKey(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationAccept => Ok(AnyToDeviceEventContent::KeyVerificationAccept(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationMac => Ok(AnyToDeviceEventContent::KeyVerificationMac(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
EventType::KeyVerificationCancel => Ok(AnyToDeviceEventContent::KeyVerificationCancel(
|
|
||||||
serde_json::from_value(json).map_err(|_| ())?,
|
|
||||||
)
|
|
||||||
.into()),
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl TryFrom<OutgoingRequest> for OutgoingContent {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(value: OutgoingRequest) -> Result<Self, ()> {
|
|
||||||
match value.request() {
|
|
||||||
crate::OutgoingRequests::KeysUpload(_) => Err(()),
|
|
||||||
crate::OutgoingRequests::KeysQuery(_) => Err(()),
|
|
||||||
crate::OutgoingRequests::ToDeviceRequest(r) => Self::try_from(r.clone()),
|
|
||||||
crate::OutgoingRequests::SignatureUpload(_) => Err(()),
|
|
||||||
crate::OutgoingRequests::RoomMessage(r) => Ok(Self::from(r.clone())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,6 @@ use matrix_sdk_common::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
event_enums::OutgoingContent,
|
|
||||||
sas_state::{
|
sas_state::{
|
||||||
Accepted, Confirmed, Created, KeyReceived, MacReceived, SasState, Started, WaitingForDone,
|
Accepted, Confirmed, Created, KeyReceived, MacReceived, SasState, Started, WaitingForDone,
|
||||||
},
|
},
|
||||||
|
@ -31,7 +30,7 @@ use super::{
|
||||||
use crate::{
|
use crate::{
|
||||||
identities::{ReadOnlyDevice, UserIdentities},
|
identities::{ReadOnlyDevice, UserIdentities},
|
||||||
verification::{
|
verification::{
|
||||||
event_enums::{AnyVerificationContent, OwnedAcceptContent, StartContent},
|
event_enums::{AnyVerificationContent, OutgoingContent, OwnedAcceptContent, StartContent},
|
||||||
Cancelled, Done,
|
Cancelled, Done,
|
||||||
},
|
},
|
||||||
ReadOnlyAccount,
|
ReadOnlyAccount,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
// 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.
|
||||||
|
|
||||||
mod event_enums;
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod inner_sas;
|
mod inner_sas;
|
||||||
mod sas_state;
|
mod sas_state;
|
||||||
|
@ -21,7 +20,6 @@ use std::sync::{Arc, Mutex};
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
pub use event_enums::OutgoingContent;
|
|
||||||
pub use helpers::content_to_request;
|
pub use helpers::content_to_request;
|
||||||
use inner_sas::InnerSas;
|
use inner_sas::InnerSas;
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
|
@ -40,7 +38,7 @@ use matrix_sdk_common::{
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
event_enums::{AnyVerificationContent, OwnedAcceptContent, StartContent},
|
event_enums::{AnyVerificationContent, OutgoingContent, OwnedAcceptContent, StartContent},
|
||||||
FlowId, IdentitiesBeingVerified, VerificationResult,
|
FlowId, IdentitiesBeingVerified, VerificationResult,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -494,9 +492,8 @@ mod test {
|
||||||
use crate::{
|
use crate::{
|
||||||
olm::PrivateCrossSigningIdentity,
|
olm::PrivateCrossSigningIdentity,
|
||||||
store::{CryptoStore, MemoryStore},
|
store::{CryptoStore, MemoryStore},
|
||||||
verification::{
|
verification::event_enums::{
|
||||||
event_enums::{AcceptContent, KeyContent, MacContent, StartContent},
|
AcceptContent, KeyContent, MacContent, OutgoingContent, StartContent,
|
||||||
sas::OutgoingContent,
|
|
||||||
},
|
},
|
||||||
ReadOnlyAccount, ReadOnlyDevice,
|
ReadOnlyAccount, ReadOnlyDevice,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue