Upgrade ruma to 0.1.0 (crates.io release)
parent
5059d8b2c6
commit
cd77441d1b
|
@ -2394,7 +2394,7 @@ mod test {
|
||||||
api::r0::{
|
api::r0::{
|
||||||
account::register::Request as RegistrationRequest,
|
account::register::Request as RegistrationRequest,
|
||||||
directory::get_public_rooms_filtered::Request as PublicRoomsFilterRequest,
|
directory::get_public_rooms_filtered::Request as PublicRoomsFilterRequest,
|
||||||
membership::Invite3pid, session::get_login_types::LoginType, uiaa::AuthData,
|
membership::Invite3pidInit, session::get_login_types::LoginType, uiaa::AuthData,
|
||||||
},
|
},
|
||||||
assign,
|
assign,
|
||||||
directory::Filter,
|
directory::Filter,
|
||||||
|
@ -2792,12 +2792,15 @@ mod test {
|
||||||
|
|
||||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||||
|
|
||||||
room.invite_user_by_3pid(Invite3pid {
|
room.invite_user_by_3pid(
|
||||||
id_server: "example.org",
|
Invite3pidInit {
|
||||||
id_access_token: "IdToken",
|
id_server: "example.org",
|
||||||
medium: thirdparty::Medium::Email,
|
id_access_token: "IdToken",
|
||||||
address: "address",
|
medium: thirdparty::Medium::Email,
|
||||||
})
|
address: "address",
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -3053,13 +3056,9 @@ mod test {
|
||||||
let room = client.get_joined_room(&room_id).unwrap();
|
let room = client.get_joined_room(&room_id).unwrap();
|
||||||
|
|
||||||
let avatar_url = mxc_uri!("mxc://example.org/avA7ar");
|
let avatar_url = mxc_uri!("mxc://example.org/avA7ar");
|
||||||
let member_event = MemberEventContent {
|
let member_event = assign!(MemberEventContent::new(MembershipState::Join), {
|
||||||
avatar_url: Some(avatar_url),
|
avatar_url: Some(avatar_url)
|
||||||
membership: MembershipState::Join,
|
});
|
||||||
is_direct: None,
|
|
||||||
displayname: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
};
|
|
||||||
let content = AnyStateEventContent::RoomMember(member_event);
|
let content = AnyStateEventContent::RoomMember(member_event);
|
||||||
let response = room.send_state_event(content, "").await.unwrap();
|
let response = room.send_state_event(content, "").await.unwrap();
|
||||||
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);
|
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);
|
||||||
|
|
|
@ -4,8 +4,6 @@ use std::{io::Read, ops::Deref};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use matrix_sdk_base::crypto::AttachmentEncryptor;
|
use matrix_sdk_base::crypto::AttachmentEncryptor;
|
||||||
#[cfg(feature = "encryption")]
|
|
||||||
use matrix_sdk_common::locks::Mutex;
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::{
|
api::r0::{
|
||||||
membership::{
|
membership::{
|
||||||
|
@ -36,6 +34,8 @@ use matrix_sdk_common::{
|
||||||
receipt::ReceiptType,
|
receipt::ReceiptType,
|
||||||
uuid::Uuid,
|
uuid::Uuid,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "encryption")]
|
||||||
|
use matrix_sdk_common::{events::room::EncryptedFileInit, locks::Mutex};
|
||||||
use mime::{self, Mime};
|
use mime::{self, Mime};
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
@ -462,15 +462,18 @@ impl Joined {
|
||||||
let response = self.client.upload(&content_type, &mut reader).await?;
|
let response = self.client.upload(&content_type, &mut reader).await?;
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
let keys = {
|
let keys: Option<Box<EncryptedFile>> = {
|
||||||
let keys = reader.finish();
|
let keys = reader.finish();
|
||||||
Some(Box::new(EncryptedFile {
|
Some(Box::new(
|
||||||
url: response.content_uri.clone(),
|
EncryptedFileInit {
|
||||||
key: keys.web_key,
|
url: response.content_uri.clone(),
|
||||||
iv: keys.iv,
|
key: keys.web_key,
|
||||||
hashes: keys.hashes,
|
iv: keys.iv,
|
||||||
v: keys.version,
|
hashes: keys.hashes,
|
||||||
}))
|
v: keys.version,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
))
|
||||||
};
|
};
|
||||||
#[cfg(not(feature = "encryption"))]
|
#[cfg(not(feature = "encryption"))]
|
||||||
let keys: Option<Box<EncryptedFile>> = None;
|
let keys: Option<Box<EncryptedFile>> = None;
|
||||||
|
@ -486,32 +489,23 @@ impl Joined {
|
||||||
let content = match content_type.type_() {
|
let content = match content_type.type_() {
|
||||||
mime::IMAGE => {
|
mime::IMAGE => {
|
||||||
// TODO create a thumbnail using the image crate?.
|
// TODO create a thumbnail using the image crate?.
|
||||||
MessageType::Image(ImageMessageEventContent {
|
MessageType::Image(assign!(
|
||||||
body: body.to_owned(),
|
ImageMessageEventContent::plain(body.to_owned(), url, None),
|
||||||
info: None,
|
{ file: encrypted_file }
|
||||||
url: Some(url),
|
))
|
||||||
file: encrypted_file,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
mime::AUDIO => MessageType::Audio(AudioMessageEventContent {
|
mime::AUDIO => MessageType::Audio(assign!(
|
||||||
body: body.to_owned(),
|
AudioMessageEventContent::plain(body.to_owned(), url, None),
|
||||||
info: None,
|
{ file: encrypted_file }
|
||||||
url: Some(url),
|
)),
|
||||||
file: encrypted_file,
|
mime::VIDEO => MessageType::Video(assign!(
|
||||||
}),
|
VideoMessageEventContent::plain(body.to_owned(), url, None),
|
||||||
mime::VIDEO => MessageType::Video(VideoMessageEventContent {
|
{ file: encrypted_file }
|
||||||
body: body.to_owned(),
|
)),
|
||||||
info: None,
|
_ => MessageType::File(assign!(
|
||||||
url: Some(url),
|
FileMessageEventContent::plain(body.to_owned(), url, None),
|
||||||
file: encrypted_file,
|
{ file: encrypted_file }
|
||||||
}),
|
)),
|
||||||
_ => MessageType::File(FileMessageEventContent {
|
|
||||||
filename: None,
|
|
||||||
body: body.to_owned(),
|
|
||||||
info: None,
|
|
||||||
url: Some(url),
|
|
||||||
file: encrypted_file,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send(AnyMessageEventContent::RoomMessage(MessageEventContent::new(content)), txn_id)
|
self.send(AnyMessageEventContent::RoomMessage(MessageEventContent::new(content)), txn_id)
|
||||||
|
@ -540,6 +534,7 @@ impl Joined {
|
||||||
/// room::member::{MemberEventContent, MembershipState},
|
/// room::member::{MemberEventContent, MembershipState},
|
||||||
/// },
|
/// },
|
||||||
/// identifiers::mxc_uri,
|
/// identifiers::mxc_uri,
|
||||||
|
/// assign,
|
||||||
/// };
|
/// };
|
||||||
/// # futures::executor::block_on(async {
|
/// # futures::executor::block_on(async {
|
||||||
/// # let homeserver = url::Url::parse("http://localhost:8080").unwrap();
|
/// # let homeserver = url::Url::parse("http://localhost:8080").unwrap();
|
||||||
|
@ -547,13 +542,9 @@ impl Joined {
|
||||||
/// # let room_id = matrix_sdk::identifiers::room_id!("!test:localhost");
|
/// # let room_id = matrix_sdk::identifiers::room_id!("!test:localhost");
|
||||||
///
|
///
|
||||||
/// let avatar_url = mxc_uri!("mxc://example.org/avatar");
|
/// let avatar_url = mxc_uri!("mxc://example.org/avatar");
|
||||||
/// let member_event = MemberEventContent {
|
/// let member_event = assign!(MemberEventContent::new(MembershipState::Join), {
|
||||||
/// avatar_url: Some(avatar_url),
|
/// avatar_url: Some(avatar_url),
|
||||||
/// membership: MembershipState::Join,
|
/// });
|
||||||
/// is_direct: None,
|
|
||||||
/// displayname: None,
|
|
||||||
/// third_party_invite: None,
|
|
||||||
/// };
|
|
||||||
/// # let room = client
|
/// # let room = client
|
||||||
/// # .get_joined_room(&room_id)
|
/// # .get_joined_room(&room_id)
|
||||||
/// # .unwrap();
|
/// # .unwrap();
|
||||||
|
|
|
@ -721,17 +721,9 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn membership_event() -> MemberEvent {
|
fn membership_event() -> MemberEvent {
|
||||||
let content = MemberEventContent {
|
|
||||||
avatar_url: None,
|
|
||||||
displayname: None,
|
|
||||||
is_direct: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
membership: MembershipState::Join,
|
|
||||||
};
|
|
||||||
|
|
||||||
MemberEvent {
|
MemberEvent {
|
||||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
content,
|
content: MemberEventContent::new(MembershipState::Join),
|
||||||
sender: user_id(),
|
sender: user_id(),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||||
state_key: user_id(),
|
state_key: user_id(),
|
||||||
|
|
|
@ -20,9 +20,7 @@ serde = "1.0.122"
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
|
|
||||||
[dependencies.ruma]
|
[dependencies.ruma]
|
||||||
version = "0.0.3"
|
version = "0.1.0"
|
||||||
git = "https://github.com/ruma/ruma"
|
|
||||||
rev = "e1ab817e0bef78cb8241d6d3c1ced7d6b414c7f6"
|
|
||||||
features = ["client-api-c", "compat", "unstable-pre-spec"]
|
features = ["client-api-c", "compat", "unstable-pre-spec"]
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
|
|
@ -23,7 +23,7 @@ use aes_ctr::{
|
||||||
};
|
};
|
||||||
use base64::DecodeError;
|
use base64::DecodeError;
|
||||||
use getrandom::getrandom;
|
use getrandom::getrandom;
|
||||||
use matrix_sdk_common::events::room::JsonWebKey;
|
use matrix_sdk_common::events::room::{JsonWebKey, JsonWebKeyInit};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -201,13 +201,13 @@ impl<'a, R: Read + 'a> AttachmentEncryptor<'a, R> {
|
||||||
// initialized.
|
// initialized.
|
||||||
getrandom(&mut iv[0..8]).expect("Can't generate randomness");
|
getrandom(&mut iv[0..8]).expect("Can't generate randomness");
|
||||||
|
|
||||||
let web_key = JsonWebKey {
|
let web_key = JsonWebKey::from(JsonWebKeyInit {
|
||||||
kty: "oct".to_owned(),
|
kty: "oct".to_owned(),
|
||||||
key_ops: vec!["encrypt".to_owned(), "decrypt".to_owned()],
|
key_ops: vec!["encrypt".to_owned(), "decrypt".to_owned()],
|
||||||
alg: "A256CTR".to_owned(),
|
alg: "A256CTR".to_owned(),
|
||||||
k: encode_url_safe(&*key),
|
k: encode_url_safe(&*key),
|
||||||
ext: true,
|
ext: true,
|
||||||
};
|
});
|
||||||
let encoded_iv = encode(&*iv);
|
let encoded_iv = encode(&*iv);
|
||||||
|
|
||||||
let aes = Aes256Ctr::new_var(&*key, &*iv).expect("Cannot create AES encryption object.");
|
let aes = Aes256Ctr::new_var(&*key, &*iv).expect("Cannot create AES encryption object.");
|
||||||
|
|
|
@ -151,12 +151,12 @@ pub struct OutgoingKeyRequest {
|
||||||
|
|
||||||
impl OutgoingKeyRequest {
|
impl OutgoingKeyRequest {
|
||||||
fn to_request(&self, own_device_id: &DeviceId) -> Result<OutgoingRequest, serde_json::Error> {
|
fn to_request(&self, own_device_id: &DeviceId) -> Result<OutgoingRequest, serde_json::Error> {
|
||||||
let content = RoomKeyRequestToDeviceEventContent {
|
let content = RoomKeyRequestToDeviceEventContent::new(
|
||||||
action: Action::Request,
|
Action::Request,
|
||||||
request_id: self.request_id.to_string(),
|
Some(self.info.clone()),
|
||||||
requesting_device_id: own_device_id.to_owned(),
|
own_device_id.to_owned(),
|
||||||
body: Some(self.info.clone()),
|
self.request_id.to_string(),
|
||||||
};
|
);
|
||||||
|
|
||||||
wrap_key_request_content(self.request_recipient.clone(), self.request_id, &content)
|
wrap_key_request_content(self.request_recipient.clone(), self.request_id, &content)
|
||||||
}
|
}
|
||||||
|
@ -165,12 +165,12 @@ impl OutgoingKeyRequest {
|
||||||
&self,
|
&self,
|
||||||
own_device_id: &DeviceId,
|
own_device_id: &DeviceId,
|
||||||
) -> Result<OutgoingRequest, serde_json::Error> {
|
) -> Result<OutgoingRequest, serde_json::Error> {
|
||||||
let content = RoomKeyRequestToDeviceEventContent {
|
let content = RoomKeyRequestToDeviceEventContent::new(
|
||||||
action: Action::CancelRequest,
|
Action::CancelRequest,
|
||||||
request_id: self.request_id.to_string(),
|
None,
|
||||||
requesting_device_id: own_device_id.to_owned(),
|
own_device_id.to_owned(),
|
||||||
body: None,
|
self.request_id.to_string(),
|
||||||
};
|
);
|
||||||
|
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
wrap_key_request_content(self.request_recipient.clone(), id, &content)
|
wrap_key_request_content(self.request_recipient.clone(), id, &content)
|
||||||
|
@ -584,12 +584,12 @@ impl KeyRequestMachine {
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
session_id: &str,
|
session_id: &str,
|
||||||
) -> Result<(Option<OutgoingRequest>, OutgoingRequest), CryptoStoreError> {
|
) -> Result<(Option<OutgoingRequest>, OutgoingRequest), CryptoStoreError> {
|
||||||
let key_info = RequestedKeyInfo {
|
let key_info = RequestedKeyInfo::new(
|
||||||
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
|
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
sender_key: sender_key.to_owned(),
|
sender_key.to_owned(),
|
||||||
session_id: session_id.to_owned(),
|
session_id.to_owned(),
|
||||||
};
|
);
|
||||||
|
|
||||||
let request = self.store.get_key_request_by_info(&key_info).await?;
|
let request = self.store.get_key_request_by_info(&key_info).await?;
|
||||||
|
|
||||||
|
@ -644,12 +644,12 @@ impl KeyRequestMachine {
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
session_id: &str,
|
session_id: &str,
|
||||||
) -> Result<(), CryptoStoreError> {
|
) -> Result<(), CryptoStoreError> {
|
||||||
let key_info = RequestedKeyInfo {
|
let key_info = RequestedKeyInfo::new(
|
||||||
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
|
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
sender_key: sender_key.to_owned(),
|
sender_key.to_owned(),
|
||||||
session_id: session_id.to_owned(),
|
session_id.to_owned(),
|
||||||
};
|
);
|
||||||
|
|
||||||
if self.should_request_key(&key_info).await? {
|
if self.should_request_key(&key_info).await? {
|
||||||
self.request_key_helper(key_info).await?;
|
self.request_key_helper(key_info).await?;
|
||||||
|
@ -675,12 +675,12 @@ impl KeyRequestMachine {
|
||||||
&self,
|
&self,
|
||||||
content: &ForwardedRoomKeyToDeviceEventContent,
|
content: &ForwardedRoomKeyToDeviceEventContent,
|
||||||
) -> Result<Option<OutgoingKeyRequest>, CryptoStoreError> {
|
) -> Result<Option<OutgoingKeyRequest>, CryptoStoreError> {
|
||||||
let info = RequestedKeyInfo {
|
let info = RequestedKeyInfo::new(
|
||||||
algorithm: content.algorithm.clone(),
|
content.algorithm.clone(),
|
||||||
room_id: content.room_id.clone(),
|
content.room_id.clone(),
|
||||||
sender_key: content.sender_key.clone(),
|
content.sender_key.clone(),
|
||||||
session_id: content.session_id.clone(),
|
content.session_id.clone(),
|
||||||
};
|
);
|
||||||
|
|
||||||
self.store.get_key_request_by_info(&info).await
|
self.store.get_key_request_by_info(&info).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1205,12 +1205,12 @@ mod test {
|
||||||
let (account, store, _dir) = get_loaded_store().await;
|
let (account, store, _dir) = get_loaded_store().await;
|
||||||
|
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
let info = RequestedKeyInfo {
|
let info = RequestedKeyInfo::new(
|
||||||
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
|
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||||
room_id: room_id!("!test:localhost"),
|
room_id!("!test:localhost"),
|
||||||
sender_key: "test_sender_key".to_string(),
|
"test_sender_key".to_string(),
|
||||||
session_id: "test_session_id".to_string(),
|
"test_session_id".to_string(),
|
||||||
};
|
);
|
||||||
|
|
||||||
let request = OutgoingKeyRequest {
|
let request = OutgoingKeyRequest {
|
||||||
request_recipient: account.user_id().to_owned(),
|
request_recipient: account.user_id().to_owned(),
|
||||||
|
|
|
@ -265,17 +265,17 @@ impl RequestState<Created> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_content(&self) -> KeyVerificationRequestEventContent {
|
fn as_content(&self) -> KeyVerificationRequestEventContent {
|
||||||
KeyVerificationRequestEventContent {
|
KeyVerificationRequestEventContent::new(
|
||||||
body: format!(
|
format!(
|
||||||
"{} is requesting to verify your key, but your client does not \
|
"{} is requesting to verify your key, but your client does not \
|
||||||
support in-chat key verification. You will need to use legacy \
|
support in-chat key verification. You will need to use legacy \
|
||||||
key verification to verify keys.",
|
key verification to verify keys.",
|
||||||
self.own_user_id
|
self.own_user_id
|
||||||
),
|
),
|
||||||
methods: SUPPORTED_METHODS.to_vec(),
|
SUPPORTED_METHODS.to_vec(),
|
||||||
from_device: self.own_device_id.clone(),
|
self.own_device_id.clone(),
|
||||||
to: self.other_user_id.clone(),
|
self.other_user_id.clone(),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_sent(self, response: &RoomMessageResponse) -> RequestState<Sent> {
|
fn into_sent(self, response: &RoomMessageResponse) -> RequestState<Sent> {
|
||||||
|
@ -360,11 +360,11 @@ impl RequestState<Requested> {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let content = ReadyEventContent {
|
let content = ReadyEventContent::new(
|
||||||
from_device: self.own_device_id,
|
self.own_device_id,
|
||||||
methods: self.state.methods,
|
self.state.methods,
|
||||||
relation: Relation { event_id: self.state.flow_id },
|
Relation::new(self.state.flow_id),
|
||||||
};
|
);
|
||||||
|
|
||||||
(state, content)
|
(state, content)
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,12 +315,9 @@ pub fn get_mac_content(sas: &OlmSas, ids: &SasIds, flow_id: &FlowId) -> MacConte
|
||||||
.expect("Can't calculate SAS MAC");
|
.expect("Can't calculate SAS MAC");
|
||||||
|
|
||||||
match flow_id {
|
match flow_id {
|
||||||
FlowId::ToDevice(s) => {
|
FlowId::ToDevice(s) => MacToDeviceEventContent::new(s.to_string(), mac, keys).into(),
|
||||||
MacToDeviceEventContent { transaction_id: s.to_string(), keys, mac }.into()
|
|
||||||
}
|
|
||||||
FlowId::InRoom(r, e) => {
|
FlowId::InRoom(r, e) => {
|
||||||
(r.clone(), MacEventContent { mac, keys, relation: Relation { event_id: e.clone() } })
|
(r.clone(), MacEventContent::new(mac, keys, Relation::new(e.clone()))).into()
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,13 @@ use matrix_sdk_common::{
|
||||||
events::key::verification::{
|
events::key::verification::{
|
||||||
accept::{
|
accept::{
|
||||||
AcceptEventContent, AcceptMethod, AcceptToDeviceEventContent,
|
AcceptEventContent, AcceptMethod, AcceptToDeviceEventContent,
|
||||||
MSasV1Content as AcceptV1Content, MSasV1ContentInit as AcceptV1ContentInit,
|
SasV1Content as AcceptV1Content, SasV1ContentInit as AcceptV1ContentInit,
|
||||||
},
|
},
|
||||||
cancel::{CancelCode, CancelEventContent, CancelToDeviceEventContent},
|
cancel::{CancelCode, CancelEventContent, CancelToDeviceEventContent},
|
||||||
done::DoneEventContent,
|
done::DoneEventContent,
|
||||||
key::{KeyEventContent, KeyToDeviceEventContent},
|
key::{KeyEventContent, KeyToDeviceEventContent},
|
||||||
start::{
|
start::{
|
||||||
MSasV1Content, MSasV1ContentInit, StartEventContent, StartMethod,
|
SasV1Content, SasV1ContentInit, StartEventContent, StartMethod,
|
||||||
StartToDeviceEventContent,
|
StartToDeviceEventContent,
|
||||||
},
|
},
|
||||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
|
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
|
||||||
|
@ -187,14 +187,14 @@ impl<S: Clone + std::fmt::Debug> std::fmt::Debug for SasState<S> {
|
||||||
/// The initial SAS state.
|
/// The initial SAS state.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Created {
|
pub struct Created {
|
||||||
protocol_definitions: MSasV1ContentInit,
|
protocol_definitions: SasV1ContentInit,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The initial SAS state if the other side started the SAS verification.
|
/// The initial SAS state if the other side started the SAS verification.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Started {
|
pub struct Started {
|
||||||
commitment: String,
|
commitment: String,
|
||||||
protocol_definitions: MSasV1Content,
|
protocol_definitions: SasV1Content,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The SAS state we're going to be in after the other side accepted our
|
/// The SAS state we're going to be in after the other side accepted our
|
||||||
|
@ -375,7 +375,7 @@ impl SasState<Created> {
|
||||||
last_event_time: Arc::new(Instant::now()),
|
last_event_time: Arc::new(Instant::now()),
|
||||||
|
|
||||||
state: Arc::new(Created {
|
state: Arc::new(Created {
|
||||||
protocol_definitions: MSasV1ContentInit {
|
protocol_definitions: SasV1ContentInit {
|
||||||
short_authentication_string: STRINGS.to_vec(),
|
short_authentication_string: STRINGS.to_vec(),
|
||||||
key_agreement_protocols: KEY_AGREEMENT_PROTOCOLS.to_vec(),
|
key_agreement_protocols: KEY_AGREEMENT_PROTOCOLS.to_vec(),
|
||||||
message_authentication_codes: MACS.to_vec(),
|
message_authentication_codes: MACS.to_vec(),
|
||||||
|
@ -387,24 +387,24 @@ impl SasState<Created> {
|
||||||
|
|
||||||
pub fn as_content(&self) -> StartContent {
|
pub fn as_content(&self) -> StartContent {
|
||||||
match self.verification_flow_id.as_ref() {
|
match self.verification_flow_id.as_ref() {
|
||||||
FlowId::ToDevice(s) => StartContent::ToDevice(StartToDeviceEventContent {
|
FlowId::ToDevice(s) => StartContent::ToDevice(StartToDeviceEventContent::new(
|
||||||
transaction_id: s.to_string(),
|
self.device_id().into(),
|
||||||
from_device: self.device_id().into(),
|
s.to_string(),
|
||||||
method: StartMethod::MSasV1(
|
StartMethod::SasV1(
|
||||||
MSasV1Content::new(self.state.protocol_definitions.clone())
|
SasV1Content::new(self.state.protocol_definitions.clone())
|
||||||
.expect("Invalid initial protocol definitions."),
|
.expect("Invalid initial protocol definitions."),
|
||||||
),
|
),
|
||||||
}),
|
)),
|
||||||
FlowId::InRoom(r, e) => StartContent::Room(
|
FlowId::InRoom(r, e) => StartContent::Room(
|
||||||
r.clone(),
|
r.clone(),
|
||||||
StartEventContent {
|
StartEventContent::new(
|
||||||
from_device: self.device_id().into(),
|
self.device_id().into(),
|
||||||
method: StartMethod::MSasV1(
|
StartMethod::SasV1(
|
||||||
MSasV1Content::new(self.state.protocol_definitions.clone())
|
SasV1Content::new(self.state.protocol_definitions.clone())
|
||||||
.expect("Invalid initial protocol definitions."),
|
.expect("Invalid initial protocol definitions."),
|
||||||
),
|
),
|
||||||
relation: Relation { event_id: e.clone() },
|
Relation::new(e.clone()),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ impl SasState<Started> {
|
||||||
other_identity: Option<UserIdentities>,
|
other_identity: Option<UserIdentities>,
|
||||||
content: &StartContent,
|
content: &StartContent,
|
||||||
) -> Result<SasState<Started>, SasState<Canceled>> {
|
) -> Result<SasState<Started>, SasState<Canceled>> {
|
||||||
if let StartMethod::MSasV1(method_content) = content.method() {
|
if let StartMethod::SasV1(method_content) = content.method() {
|
||||||
let sas = OlmSas::new();
|
let sas = OlmSas::new();
|
||||||
|
|
||||||
let pubkey = sas.public_key();
|
let pubkey = sas.public_key();
|
||||||
|
@ -564,14 +564,10 @@ impl SasState<Started> {
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.verification_flow_id.as_ref() {
|
match self.verification_flow_id.as_ref() {
|
||||||
FlowId::ToDevice(s) => {
|
FlowId::ToDevice(s) => AcceptToDeviceEventContent::new(s.to_string(), method).into(),
|
||||||
AcceptToDeviceEventContent { transaction_id: s.to_string(), method }.into()
|
FlowId::InRoom(r, e) => {
|
||||||
|
(r.clone(), AcceptEventContent::new(method, Relation::new(e.clone()))).into()
|
||||||
}
|
}
|
||||||
FlowId::InRoom(r, e) => (
|
|
||||||
r.clone(),
|
|
||||||
AcceptEventContent { method, relation: Relation { event_id: e.clone() } },
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,10 +674,10 @@ impl SasState<Accepted> {
|
||||||
.into(),
|
.into(),
|
||||||
FlowId::InRoom(r, e) => (
|
FlowId::InRoom(r, e) => (
|
||||||
r.clone(),
|
r.clone(),
|
||||||
KeyEventContent {
|
KeyEventContent::new(
|
||||||
key: self.inner.lock().unwrap().public_key(),
|
self.inner.lock().unwrap().public_key(),
|
||||||
relation: Relation { event_id: e.clone() },
|
Relation::new(e.clone()),
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
|
@ -702,10 +698,10 @@ impl SasState<KeyReceived> {
|
||||||
.into(),
|
.into(),
|
||||||
FlowId::InRoom(r, e) => (
|
FlowId::InRoom(r, e) => (
|
||||||
r.clone(),
|
r.clone(),
|
||||||
KeyEventContent {
|
KeyEventContent::new(
|
||||||
key: self.inner.lock().unwrap().public_key(),
|
self.inner.lock().unwrap().public_key(),
|
||||||
relation: Relation { event_id: e.clone() },
|
Relation::new(e.clone()),
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +996,7 @@ impl SasState<WaitingForDone> {
|
||||||
unreachable!("The done content isn't supported yet for to-device verifications")
|
unreachable!("The done content isn't supported yet for to-device verifications")
|
||||||
}
|
}
|
||||||
FlowId::InRoom(r, e) => {
|
FlowId::InRoom(r, e) => {
|
||||||
(r.clone(), DoneEventContent { relation: Relation { event_id: e.clone() } }).into()
|
(r.clone(), DoneEventContent::new(Relation::new(e.clone()))).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1048,7 @@ impl SasState<Done> {
|
||||||
unreachable!("The done content isn't supported yet for to-device verifications")
|
unreachable!("The done content isn't supported yet for to-device verifications")
|
||||||
}
|
}
|
||||||
FlowId::InRoom(r, e) => {
|
FlowId::InRoom(r, e) => {
|
||||||
(r.clone(), DoneEventContent { relation: Relation { event_id: e.clone() } }).into()
|
(r.clone(), DoneEventContent::new(Relation::new(e.clone()))).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1096,20 +1092,20 @@ impl Canceled {
|
||||||
impl SasState<Canceled> {
|
impl SasState<Canceled> {
|
||||||
pub fn as_content(&self) -> CancelContent {
|
pub fn as_content(&self) -> CancelContent {
|
||||||
match self.verification_flow_id.as_ref() {
|
match self.verification_flow_id.as_ref() {
|
||||||
FlowId::ToDevice(s) => CancelToDeviceEventContent {
|
FlowId::ToDevice(s) => CancelToDeviceEventContent::new(
|
||||||
transaction_id: s.clone(),
|
s.clone(),
|
||||||
reason: self.state.reason.to_string(),
|
self.state.reason.to_string(),
|
||||||
code: self.state.cancel_code.clone(),
|
self.state.cancel_code.clone(),
|
||||||
}
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
||||||
FlowId::InRoom(r, e) => (
|
FlowId::InRoom(r, e) => (
|
||||||
r.clone(),
|
r.clone(),
|
||||||
CancelEventContent {
|
CancelEventContent::new(
|
||||||
reason: self.state.reason.to_string(),
|
self.state.reason.to_string(),
|
||||||
code: self.state.cancel_code.clone(),
|
self.state.cancel_code.clone(),
|
||||||
relation: Relation { event_id: e.clone() },
|
Relation::new(e.clone()),
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
|
@ -1336,7 +1332,7 @@ mod test {
|
||||||
};
|
};
|
||||||
|
|
||||||
match method {
|
match method {
|
||||||
StartMethod::MSasV1(ref mut c) => {
|
StartMethod::SasV1(ref mut c) => {
|
||||||
c.message_authentication_codes = vec![];
|
c.message_authentication_codes = vec![];
|
||||||
}
|
}
|
||||||
_ => panic!("Unknown SAS start method"),
|
_ => panic!("Unknown SAS start method"),
|
||||||
|
|
Loading…
Reference in New Issue