Upgrade ruma to 0.1.0 (crates.io release)

master
Jonas Platte 2021-05-17 02:21:30 +02:00
parent 5059d8b2c6
commit cd77441d1b
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
10 changed files with 141 additions and 168 deletions

View File

@ -2394,7 +2394,7 @@ mod test {
api::r0::{
account::register::Request as RegistrationRequest,
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,
directory::Filter,
@ -2792,12 +2792,15 @@ mod test {
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
room.invite_user_by_3pid(Invite3pid {
room.invite_user_by_3pid(
Invite3pidInit {
id_server: "example.org",
id_access_token: "IdToken",
medium: thirdparty::Medium::Email,
address: "address",
})
}
.into(),
)
.await
.unwrap();
}
@ -3053,13 +3056,9 @@ mod test {
let room = client.get_joined_room(&room_id).unwrap();
let avatar_url = mxc_uri!("mxc://example.org/avA7ar");
let member_event = MemberEventContent {
avatar_url: Some(avatar_url),
membership: MembershipState::Join,
is_direct: None,
displayname: None,
third_party_invite: None,
};
let member_event = assign!(MemberEventContent::new(MembershipState::Join), {
avatar_url: Some(avatar_url)
});
let content = AnyStateEventContent::RoomMember(member_event);
let response = room.send_state_event(content, "").await.unwrap();
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);

View File

@ -4,8 +4,6 @@ use std::{io::Read, ops::Deref};
#[cfg(feature = "encryption")]
use matrix_sdk_base::crypto::AttachmentEncryptor;
#[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{
api::r0::{
membership::{
@ -36,6 +34,8 @@ use matrix_sdk_common::{
receipt::ReceiptType,
uuid::Uuid,
};
#[cfg(feature = "encryption")]
use matrix_sdk_common::{events::room::EncryptedFileInit, locks::Mutex};
use mime::{self, Mime};
#[cfg(feature = "encryption")]
use tracing::instrument;
@ -462,15 +462,18 @@ impl Joined {
let response = self.client.upload(&content_type, &mut reader).await?;
#[cfg(feature = "encryption")]
let keys = {
let keys: Option<Box<EncryptedFile>> = {
let keys = reader.finish();
Some(Box::new(EncryptedFile {
Some(Box::new(
EncryptedFileInit {
url: response.content_uri.clone(),
key: keys.web_key,
iv: keys.iv,
hashes: keys.hashes,
v: keys.version,
}))
}
.into(),
))
};
#[cfg(not(feature = "encryption"))]
let keys: Option<Box<EncryptedFile>> = None;
@ -486,32 +489,23 @@ impl Joined {
let content = match content_type.type_() {
mime::IMAGE => {
// TODO create a thumbnail using the image crate?.
MessageType::Image(ImageMessageEventContent {
body: body.to_owned(),
info: None,
url: Some(url),
file: encrypted_file,
})
MessageType::Image(assign!(
ImageMessageEventContent::plain(body.to_owned(), url, None),
{ file: encrypted_file }
))
}
mime::AUDIO => MessageType::Audio(AudioMessageEventContent {
body: body.to_owned(),
info: None,
url: Some(url),
file: encrypted_file,
}),
mime::VIDEO => MessageType::Video(VideoMessageEventContent {
body: body.to_owned(),
info: None,
url: Some(url),
file: encrypted_file,
}),
_ => MessageType::File(FileMessageEventContent {
filename: None,
body: body.to_owned(),
info: None,
url: Some(url),
file: encrypted_file,
}),
mime::AUDIO => MessageType::Audio(assign!(
AudioMessageEventContent::plain(body.to_owned(), url, None),
{ file: encrypted_file }
)),
mime::VIDEO => MessageType::Video(assign!(
VideoMessageEventContent::plain(body.to_owned(), url, None),
{ file: encrypted_file }
)),
_ => MessageType::File(assign!(
FileMessageEventContent::plain(body.to_owned(), url, None),
{ file: encrypted_file }
)),
};
self.send(AnyMessageEventContent::RoomMessage(MessageEventContent::new(content)), txn_id)
@ -540,6 +534,7 @@ impl Joined {
/// room::member::{MemberEventContent, MembershipState},
/// },
/// identifiers::mxc_uri,
/// assign,
/// };
/// # futures::executor::block_on(async {
/// # 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 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),
/// membership: MembershipState::Join,
/// is_direct: None,
/// displayname: None,
/// third_party_invite: None,
/// };
/// });
/// # let room = client
/// # .get_joined_room(&room_id)
/// # .unwrap();

View File

@ -721,17 +721,9 @@ mod test {
}
fn membership_event() -> MemberEvent {
let content = MemberEventContent {
avatar_url: None,
displayname: None,
is_direct: None,
third_party_invite: None,
membership: MembershipState::Join,
};
MemberEvent {
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
content,
content: MemberEventContent::new(MembershipState::Join),
sender: user_id(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
state_key: user_id(),

View File

@ -20,9 +20,7 @@ serde = "1.0.122"
async-trait = "0.1.42"
[dependencies.ruma]
version = "0.0.3"
git = "https://github.com/ruma/ruma"
rev = "e1ab817e0bef78cb8241d6d3c1ced7d6b414c7f6"
version = "0.1.0"
features = ["client-api-c", "compat", "unstable-pre-spec"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View File

@ -23,7 +23,7 @@ use aes_ctr::{
};
use base64::DecodeError;
use getrandom::getrandom;
use matrix_sdk_common::events::room::JsonWebKey;
use matrix_sdk_common::events::room::{JsonWebKey, JsonWebKeyInit};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use thiserror::Error;
@ -201,13 +201,13 @@ impl<'a, R: Read + 'a> AttachmentEncryptor<'a, R> {
// initialized.
getrandom(&mut iv[0..8]).expect("Can't generate randomness");
let web_key = JsonWebKey {
let web_key = JsonWebKey::from(JsonWebKeyInit {
kty: "oct".to_owned(),
key_ops: vec!["encrypt".to_owned(), "decrypt".to_owned()],
alg: "A256CTR".to_owned(),
k: encode_url_safe(&*key),
ext: true,
};
});
let encoded_iv = encode(&*iv);
let aes = Aes256Ctr::new_var(&*key, &*iv).expect("Cannot create AES encryption object.");

View File

@ -151,12 +151,12 @@ pub struct OutgoingKeyRequest {
impl OutgoingKeyRequest {
fn to_request(&self, own_device_id: &DeviceId) -> Result<OutgoingRequest, serde_json::Error> {
let content = RoomKeyRequestToDeviceEventContent {
action: Action::Request,
request_id: self.request_id.to_string(),
requesting_device_id: own_device_id.to_owned(),
body: Some(self.info.clone()),
};
let content = RoomKeyRequestToDeviceEventContent::new(
Action::Request,
Some(self.info.clone()),
own_device_id.to_owned(),
self.request_id.to_string(),
);
wrap_key_request_content(self.request_recipient.clone(), self.request_id, &content)
}
@ -165,12 +165,12 @@ impl OutgoingKeyRequest {
&self,
own_device_id: &DeviceId,
) -> Result<OutgoingRequest, serde_json::Error> {
let content = RoomKeyRequestToDeviceEventContent {
action: Action::CancelRequest,
request_id: self.request_id.to_string(),
requesting_device_id: own_device_id.to_owned(),
body: None,
};
let content = RoomKeyRequestToDeviceEventContent::new(
Action::CancelRequest,
None,
own_device_id.to_owned(),
self.request_id.to_string(),
);
let id = Uuid::new_v4();
wrap_key_request_content(self.request_recipient.clone(), id, &content)
@ -584,12 +584,12 @@ impl KeyRequestMachine {
sender_key: &str,
session_id: &str,
) -> Result<(Option<OutgoingRequest>, OutgoingRequest), CryptoStoreError> {
let key_info = RequestedKeyInfo {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id: room_id.to_owned(),
sender_key: sender_key.to_owned(),
session_id: session_id.to_owned(),
};
let key_info = RequestedKeyInfo::new(
EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id.to_owned(),
sender_key.to_owned(),
session_id.to_owned(),
);
let request = self.store.get_key_request_by_info(&key_info).await?;
@ -644,12 +644,12 @@ impl KeyRequestMachine {
sender_key: &str,
session_id: &str,
) -> Result<(), CryptoStoreError> {
let key_info = RequestedKeyInfo {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id: room_id.to_owned(),
sender_key: sender_key.to_owned(),
session_id: session_id.to_owned(),
};
let key_info = RequestedKeyInfo::new(
EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id.to_owned(),
sender_key.to_owned(),
session_id.to_owned(),
);
if self.should_request_key(&key_info).await? {
self.request_key_helper(key_info).await?;
@ -675,12 +675,12 @@ impl KeyRequestMachine {
&self,
content: &ForwardedRoomKeyToDeviceEventContent,
) -> Result<Option<OutgoingKeyRequest>, CryptoStoreError> {
let info = RequestedKeyInfo {
algorithm: content.algorithm.clone(),
room_id: content.room_id.clone(),
sender_key: content.sender_key.clone(),
session_id: content.session_id.clone(),
};
let info = RequestedKeyInfo::new(
content.algorithm.clone(),
content.room_id.clone(),
content.sender_key.clone(),
content.session_id.clone(),
);
self.store.get_key_request_by_info(&info).await
}

View File

@ -1205,12 +1205,12 @@ mod test {
let (account, store, _dir) = get_loaded_store().await;
let id = Uuid::new_v4();
let info = RequestedKeyInfo {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id: room_id!("!test:localhost"),
sender_key: "test_sender_key".to_string(),
session_id: "test_session_id".to_string(),
};
let info = RequestedKeyInfo::new(
EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id!("!test:localhost"),
"test_sender_key".to_string(),
"test_session_id".to_string(),
);
let request = OutgoingKeyRequest {
request_recipient: account.user_id().to_owned(),

View File

@ -265,17 +265,17 @@ impl RequestState<Created> {
}
fn as_content(&self) -> KeyVerificationRequestEventContent {
KeyVerificationRequestEventContent {
body: format!(
KeyVerificationRequestEventContent::new(
format!(
"{} is requesting to verify your key, but your client does not \
support in-chat key verification. You will need to use legacy \
key verification to verify keys.",
self.own_user_id
),
methods: SUPPORTED_METHODS.to_vec(),
from_device: self.own_device_id.clone(),
to: self.other_user_id.clone(),
}
SUPPORTED_METHODS.to_vec(),
self.own_device_id.clone(),
self.other_user_id.clone(),
)
}
fn into_sent(self, response: &RoomMessageResponse) -> RequestState<Sent> {
@ -360,11 +360,11 @@ impl RequestState<Requested> {
},
};
let content = ReadyEventContent {
from_device: self.own_device_id,
methods: self.state.methods,
relation: Relation { event_id: self.state.flow_id },
};
let content = ReadyEventContent::new(
self.own_device_id,
self.state.methods,
Relation::new(self.state.flow_id),
);
(state, content)
}

View File

@ -315,12 +315,9 @@ pub fn get_mac_content(sas: &OlmSas, ids: &SasIds, flow_id: &FlowId) -> MacConte
.expect("Can't calculate SAS MAC");
match flow_id {
FlowId::ToDevice(s) => {
MacToDeviceEventContent { transaction_id: s.to_string(), keys, mac }.into()
}
FlowId::ToDevice(s) => MacToDeviceEventContent::new(s.to_string(), mac, keys).into(),
FlowId::InRoom(r, e) => {
(r.clone(), MacEventContent { mac, keys, relation: Relation { event_id: e.clone() } })
.into()
(r.clone(), MacEventContent::new(mac, keys, Relation::new(e.clone()))).into()
}
}
}

View File

@ -23,13 +23,13 @@ use matrix_sdk_common::{
events::key::verification::{
accept::{
AcceptEventContent, AcceptMethod, AcceptToDeviceEventContent,
MSasV1Content as AcceptV1Content, MSasV1ContentInit as AcceptV1ContentInit,
SasV1Content as AcceptV1Content, SasV1ContentInit as AcceptV1ContentInit,
},
cancel::{CancelCode, CancelEventContent, CancelToDeviceEventContent},
done::DoneEventContent,
key::{KeyEventContent, KeyToDeviceEventContent},
start::{
MSasV1Content, MSasV1ContentInit, StartEventContent, StartMethod,
SasV1Content, SasV1ContentInit, StartEventContent, StartMethod,
StartToDeviceEventContent,
},
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
@ -187,14 +187,14 @@ impl<S: Clone + std::fmt::Debug> std::fmt::Debug for SasState<S> {
/// The initial SAS state.
#[derive(Clone, Debug)]
pub struct Created {
protocol_definitions: MSasV1ContentInit,
protocol_definitions: SasV1ContentInit,
}
/// The initial SAS state if the other side started the SAS verification.
#[derive(Clone, Debug)]
pub struct Started {
commitment: String,
protocol_definitions: MSasV1Content,
protocol_definitions: SasV1Content,
}
/// 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()),
state: Arc::new(Created {
protocol_definitions: MSasV1ContentInit {
protocol_definitions: SasV1ContentInit {
short_authentication_string: STRINGS.to_vec(),
key_agreement_protocols: KEY_AGREEMENT_PROTOCOLS.to_vec(),
message_authentication_codes: MACS.to_vec(),
@ -387,24 +387,24 @@ impl SasState<Created> {
pub fn as_content(&self) -> StartContent {
match self.verification_flow_id.as_ref() {
FlowId::ToDevice(s) => StartContent::ToDevice(StartToDeviceEventContent {
transaction_id: s.to_string(),
from_device: self.device_id().into(),
method: StartMethod::MSasV1(
MSasV1Content::new(self.state.protocol_definitions.clone())
FlowId::ToDevice(s) => StartContent::ToDevice(StartToDeviceEventContent::new(
self.device_id().into(),
s.to_string(),
StartMethod::SasV1(
SasV1Content::new(self.state.protocol_definitions.clone())
.expect("Invalid initial protocol definitions."),
),
}),
)),
FlowId::InRoom(r, e) => StartContent::Room(
r.clone(),
StartEventContent {
from_device: self.device_id().into(),
method: StartMethod::MSasV1(
MSasV1Content::new(self.state.protocol_definitions.clone())
StartEventContent::new(
self.device_id().into(),
StartMethod::SasV1(
SasV1Content::new(self.state.protocol_definitions.clone())
.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>,
content: &StartContent,
) -> 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 pubkey = sas.public_key();
@ -564,14 +564,10 @@ impl SasState<Started> {
);
match self.verification_flow_id.as_ref() {
FlowId::ToDevice(s) => {
AcceptToDeviceEventContent { transaction_id: s.to_string(), method }.into()
FlowId::ToDevice(s) => AcceptToDeviceEventContent::new(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(),
FlowId::InRoom(r, e) => (
r.clone(),
KeyEventContent {
key: self.inner.lock().unwrap().public_key(),
relation: Relation { event_id: e.clone() },
},
KeyEventContent::new(
self.inner.lock().unwrap().public_key(),
Relation::new(e.clone()),
),
)
.into(),
}
@ -702,10 +698,10 @@ impl SasState<KeyReceived> {
.into(),
FlowId::InRoom(r, e) => (
r.clone(),
KeyEventContent {
key: self.inner.lock().unwrap().public_key(),
relation: Relation { event_id: e.clone() },
},
KeyEventContent::new(
self.inner.lock().unwrap().public_key(),
Relation::new(e.clone()),
),
)
.into(),
}
@ -1000,7 +996,7 @@ impl SasState<WaitingForDone> {
unreachable!("The done content isn't supported yet for to-device verifications")
}
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")
}
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> {
pub fn as_content(&self) -> CancelContent {
match self.verification_flow_id.as_ref() {
FlowId::ToDevice(s) => CancelToDeviceEventContent {
transaction_id: s.clone(),
reason: self.state.reason.to_string(),
code: self.state.cancel_code.clone(),
}
FlowId::ToDevice(s) => CancelToDeviceEventContent::new(
s.clone(),
self.state.reason.to_string(),
self.state.cancel_code.clone(),
)
.into(),
FlowId::InRoom(r, e) => (
r.clone(),
CancelEventContent {
reason: self.state.reason.to_string(),
code: self.state.cancel_code.clone(),
relation: Relation { event_id: e.clone() },
},
CancelEventContent::new(
self.state.reason.to_string(),
self.state.cancel_code.clone(),
Relation::new(e.clone()),
),
)
.into(),
}
@ -1336,7 +1332,7 @@ mod test {
};
match method {
StartMethod::MSasV1(ref mut c) => {
StartMethod::SasV1(ref mut c) => {
c.message_authentication_codes = vec![];
}
_ => panic!("Unknown SAS start method"),