crypto: Fix a bunch of clippy warnings.
parent
897c6abe92
commit
1fd8c2052e
|
@ -1165,7 +1165,7 @@ impl Client {
|
||||||
request: &RoomMessageRequest,
|
request: &RoomMessageRequest,
|
||||||
) -> Result<send_message_event::Response> {
|
) -> Result<send_message_event::Response> {
|
||||||
let content = request.content.clone();
|
let content = request.content.clone();
|
||||||
let txn_id = request.txn_id.into();
|
let txn_id = request.txn_id;
|
||||||
let room_id = &request.room_id;
|
let room_id = &request.room_id;
|
||||||
|
|
||||||
self.room_send(&room_id, content, Some(txn_id)).await
|
self.room_send(&room_id, content, Some(txn_id)).await
|
||||||
|
|
|
@ -743,8 +743,8 @@ impl OlmMachine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_verification_event(&self, mut event: &mut AnyToDeviceEvent) {
|
async fn handle_verification_event(&self, event: &AnyToDeviceEvent) {
|
||||||
if let Err(e) = self.verification_machine.receive_event(&mut event).await {
|
if let Err(e) = self.verification_machine.receive_event(&event).await {
|
||||||
error!("Error handling a verification event: {:?}", e);
|
error!("Error handling a verification event: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -879,7 +879,7 @@ impl OlmMachine {
|
||||||
| AnyToDeviceEvent::KeyVerificationMac(..)
|
| AnyToDeviceEvent::KeyVerificationMac(..)
|
||||||
| AnyToDeviceEvent::KeyVerificationRequest(..)
|
| AnyToDeviceEvent::KeyVerificationRequest(..)
|
||||||
| AnyToDeviceEvent::KeyVerificationStart(..) => {
|
| AnyToDeviceEvent::KeyVerificationStart(..) => {
|
||||||
self.handle_verification_event(&mut event).await;
|
self.handle_verification_event(&event).await;
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
@ -1826,34 +1826,34 @@ pub(crate) mod test {
|
||||||
|
|
||||||
let (alice_sas, request) = bob_device.start_verification().await.unwrap();
|
let (alice_sas, request) = bob_device.start_verification().await.unwrap();
|
||||||
|
|
||||||
let mut event = request_to_event(alice.user_id(), &request.into());
|
let event = request_to_event(alice.user_id(), &request.into());
|
||||||
bob.handle_verification_event(&mut event).await;
|
bob.handle_verification_event(&event).await;
|
||||||
|
|
||||||
let bob_sas = bob.get_verification(alice_sas.flow_id().as_str()).unwrap();
|
let bob_sas = bob.get_verification(alice_sas.flow_id().as_str()).unwrap();
|
||||||
|
|
||||||
assert!(alice_sas.emoji().is_none());
|
assert!(alice_sas.emoji().is_none());
|
||||||
assert!(bob_sas.emoji().is_none());
|
assert!(bob_sas.emoji().is_none());
|
||||||
|
|
||||||
let mut event = bob_sas
|
let event = bob_sas
|
||||||
.accept()
|
.accept()
|
||||||
.map(|r| request_to_event(bob.user_id(), &r))
|
.map(|r| request_to_event(bob.user_id(), &r))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
alice.handle_verification_event(&mut event).await;
|
alice.handle_verification_event(&event).await;
|
||||||
|
|
||||||
let mut event = alice
|
let event = alice
|
||||||
.outgoing_to_device_requests()
|
.outgoing_to_device_requests()
|
||||||
.first()
|
.first()
|
||||||
.map(|r| outgoing_request_to_event(alice.user_id(), r))
|
.map(|r| outgoing_request_to_event(alice.user_id(), r))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
bob.handle_verification_event(&mut event).await;
|
bob.handle_verification_event(&event).await;
|
||||||
|
|
||||||
let mut event = bob
|
let event = bob
|
||||||
.outgoing_to_device_requests()
|
.outgoing_to_device_requests()
|
||||||
.first()
|
.first()
|
||||||
.map(|r| outgoing_request_to_event(bob.user_id(), r))
|
.map(|r| outgoing_request_to_event(bob.user_id(), r))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
alice.handle_verification_event(&mut event).await;
|
alice.handle_verification_event(&event).await;
|
||||||
|
|
||||||
assert!(alice_sas.emoji().is_some());
|
assert!(alice_sas.emoji().is_some());
|
||||||
assert!(bob_sas.emoji().is_some());
|
assert!(bob_sas.emoji().is_some());
|
||||||
|
@ -1861,19 +1861,19 @@ pub(crate) mod test {
|
||||||
assert_eq!(alice_sas.emoji(), bob_sas.emoji());
|
assert_eq!(alice_sas.emoji(), bob_sas.emoji());
|
||||||
assert_eq!(alice_sas.decimals(), bob_sas.decimals());
|
assert_eq!(alice_sas.decimals(), bob_sas.decimals());
|
||||||
|
|
||||||
let mut event = bob_sas
|
let event = bob_sas
|
||||||
.confirm()
|
.confirm()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.map(|r| request_to_event(bob.user_id(), &r))
|
.map(|r| request_to_event(bob.user_id(), &r))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
alice.handle_verification_event(&mut event).await;
|
alice.handle_verification_event(&event).await;
|
||||||
|
|
||||||
assert!(!alice_sas.is_done());
|
assert!(!alice_sas.is_done());
|
||||||
assert!(!bob_sas.is_done());
|
assert!(!bob_sas.is_done());
|
||||||
|
|
||||||
let mut event = alice_sas
|
let event = alice_sas
|
||||||
.confirm()
|
.confirm()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1891,7 +1891,7 @@ pub(crate) mod test {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(!alice_device.is_trusted());
|
assert!(!alice_device.is_trusted());
|
||||||
bob.handle_verification_event(&mut event).await;
|
bob.handle_verification_event(&event).await;
|
||||||
assert!(bob_sas.is_done());
|
assert!(bob_sas.is_done());
|
||||||
assert!(alice_device.is_trusted());
|
assert!(alice_device.is_trusted());
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl VerificationMachine {
|
||||||
let request = content_to_request(device.user_id(), device.device_id(), c);
|
let request = content_to_request(device.user_id(), device.device_id(), c);
|
||||||
|
|
||||||
self.verifications
|
self.verifications
|
||||||
.insert(sas.flow_id().to_string(), sas.clone());
|
.insert(sas.flow_id().as_str().to_owned(), sas.clone());
|
||||||
|
|
||||||
request.into()
|
request.into()
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ impl VerificationMachine {
|
||||||
request: Arc::new(
|
request: Arc::new(
|
||||||
RoomMessageRequest {
|
RoomMessageRequest {
|
||||||
room_id: r,
|
room_id: r,
|
||||||
txn_id: request_id.clone(),
|
txn_id: request_id,
|
||||||
content: c,
|
content: c,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -512,7 +512,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
machine
|
machine
|
||||||
.receive_event(&mut wrap_any_to_device_content(
|
.receive_event(&wrap_any_to_device_content(
|
||||||
bob_sas.user_id(),
|
bob_sas.user_id(),
|
||||||
start_content.into(),
|
start_content.into(),
|
||||||
))
|
))
|
||||||
|
@ -536,18 +536,18 @@ mod test {
|
||||||
|
|
||||||
let alice = alice_machine.get_sas(bob.flow_id().as_str()).unwrap();
|
let alice = alice_machine.get_sas(bob.flow_id().as_str()).unwrap();
|
||||||
|
|
||||||
let mut event = alice
|
let event = alice
|
||||||
.accept()
|
.accept()
|
||||||
.map(|c| wrap_any_to_device_content(alice.user_id(), get_content_from_request(&c)))
|
.map(|c| wrap_any_to_device_content(alice.user_id(), get_content_from_request(&c)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut event = bob
|
let event = bob
|
||||||
.receive_event(&mut event)
|
.receive_event(&event)
|
||||||
.map(|c| wrap_any_to_device_content(bob.user_id(), c))
|
.map(|c| wrap_any_to_device_content(bob.user_id(), c))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(alice_machine.outgoing_to_device_messages.is_empty());
|
assert!(alice_machine.outgoing_to_device_messages.is_empty());
|
||||||
alice_machine.receive_event(&mut event).await.unwrap();
|
alice_machine.receive_event(&event).await.unwrap();
|
||||||
assert!(!alice_machine.outgoing_to_device_messages.is_empty());
|
assert!(!alice_machine.outgoing_to_device_messages.is_empty());
|
||||||
|
|
||||||
let request = alice_machine
|
let request = alice_machine
|
||||||
|
@ -564,29 +564,29 @@ mod test {
|
||||||
panic!("Invalid request type");
|
panic!("Invalid request type");
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut event =
|
let event =
|
||||||
wrap_any_to_device_content(alice.user_id(), get_content_from_request(&r.into()));
|
wrap_any_to_device_content(alice.user_id(), get_content_from_request(&r.into()));
|
||||||
drop(request);
|
drop(request);
|
||||||
alice_machine.mark_request_as_sent(&txn_id);
|
alice_machine.mark_request_as_sent(&txn_id);
|
||||||
|
|
||||||
assert!(bob.receive_event(&mut event).is_none());
|
assert!(bob.receive_event(&event).is_none());
|
||||||
|
|
||||||
assert!(alice.emoji().is_some());
|
assert!(alice.emoji().is_some());
|
||||||
assert!(bob.emoji().is_some());
|
assert!(bob.emoji().is_some());
|
||||||
|
|
||||||
assert_eq!(alice.emoji(), bob.emoji());
|
assert_eq!(alice.emoji(), bob.emoji());
|
||||||
|
|
||||||
let mut event = wrap_any_to_device_content(
|
let event = wrap_any_to_device_content(
|
||||||
alice.user_id(),
|
alice.user_id(),
|
||||||
get_content_from_request(&alice.confirm().await.unwrap().0.unwrap()),
|
get_content_from_request(&alice.confirm().await.unwrap().0.unwrap()),
|
||||||
);
|
);
|
||||||
bob.receive_event(&mut event);
|
bob.receive_event(&event);
|
||||||
|
|
||||||
let mut event = wrap_any_to_device_content(
|
let event = wrap_any_to_device_content(
|
||||||
bob.user_id(),
|
bob.user_id(),
|
||||||
get_content_from_request(&bob.confirm().await.unwrap().0.unwrap()),
|
get_content_from_request(&bob.confirm().await.unwrap().0.unwrap()),
|
||||||
);
|
);
|
||||||
alice.receive_event(&mut event);
|
alice.receive_event(&event);
|
||||||
|
|
||||||
assert!(alice.is_done());
|
assert!(alice.is_done());
|
||||||
assert!(bob.is_done());
|
assert!(bob.is_done());
|
||||||
|
|
|
@ -86,13 +86,13 @@ impl VerificationRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn into_started_sas(
|
pub(crate) fn into_started_sas(
|
||||||
&self,
|
self,
|
||||||
event: &SyncMessageEvent<StartEventContent>,
|
event: &SyncMessageEvent<StartEventContent>,
|
||||||
device: ReadOnlyDevice,
|
device: ReadOnlyDevice,
|
||||||
user_identity: Option<UserIdentities>,
|
user_identity: Option<UserIdentities>,
|
||||||
) -> Result<Sas, OutgoingContent> {
|
) -> Result<Sas, OutgoingContent> {
|
||||||
match &*self.inner.lock().unwrap() {
|
match &*self.inner.lock().unwrap() {
|
||||||
InnerRequest::Ready(s) => s.into_started_sas(
|
InnerRequest::Ready(s) => s.clone().into_started_sas(
|
||||||
&event.clone().into_full_event(self.room_id().clone()),
|
&event.clone().into_full_event(self.room_id().clone()),
|
||||||
self.store.clone(),
|
self.store.clone(),
|
||||||
self.account.clone(),
|
self.account.clone(),
|
||||||
|
@ -129,7 +129,7 @@ impl InnerRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_started_sas(
|
fn into_started_sas(
|
||||||
&mut self,
|
self,
|
||||||
event: &MessageEvent<StartEventContent>,
|
event: &MessageEvent<StartEventContent>,
|
||||||
store: Arc<Box<dyn CryptoStore>>,
|
store: Arc<Box<dyn CryptoStore>>,
|
||||||
account: ReadOnlyAccount,
|
account: ReadOnlyAccount,
|
||||||
|
@ -193,8 +193,7 @@ impl RequestState<Created> {
|
||||||
state: Sent {
|
state: Sent {
|
||||||
methods: SUPPORTED_METHODS.to_vec(),
|
methods: SUPPORTED_METHODS.to_vec(),
|
||||||
flow_id: response.event_id.clone(),
|
flow_id: response.event_id.clone(),
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,9 +218,8 @@ impl RequestState<Sent> {
|
||||||
state: Ready {
|
state: Ready {
|
||||||
methods: content.methods.to_owned(),
|
methods: content.methods.to_owned(),
|
||||||
other_device_id: content.from_device.clone(),
|
other_device_id: content.from_device.clone(),
|
||||||
flow_id: self.state.flow_id.clone(),
|
flow_id: self.state.flow_id,
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,8 +254,7 @@ impl RequestState<Requested> {
|
||||||
methods: content.methods.clone(),
|
methods: content.methods.clone(),
|
||||||
flow_id: event_id.clone(),
|
flow_id: event_id.clone(),
|
||||||
other_device_id: content.from_device.clone(),
|
other_device_id: content.from_device.clone(),
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +297,7 @@ struct Ready {
|
||||||
|
|
||||||
impl RequestState<Ready> {
|
impl RequestState<Ready> {
|
||||||
fn into_started_sas(
|
fn into_started_sas(
|
||||||
&self,
|
self,
|
||||||
event: &MessageEvent<StartEventContent>,
|
event: &MessageEvent<StartEventContent>,
|
||||||
store: Arc<Box<dyn CryptoStore>>,
|
store: Arc<Box<dyn CryptoStore>>,
|
||||||
account: ReadOnlyAccount,
|
account: ReadOnlyAccount,
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl StartContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_canonical_json(self) -> CanonicalJsonValue {
|
pub fn canonical_json(self) -> CanonicalJsonValue {
|
||||||
let content = match self {
|
let content = match self {
|
||||||
StartContent::ToDevice(c) => serde_json::to_value(c),
|
StartContent::ToDevice(c) => serde_json::to_value(c),
|
||||||
StartContent::Room(_, c) => serde_json::to_value(c),
|
StartContent::Room(_, c) => serde_json::to_value(c),
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub struct SasIds {
|
||||||
/// * `content` - The `m.key.verification.start` event content that started the
|
/// * `content` - The `m.key.verification.start` event content that started the
|
||||||
/// interactive verification process.
|
/// interactive verification process.
|
||||||
pub fn calculate_commitment(public_key: &str, content: impl Into<StartContent>) -> String {
|
pub fn calculate_commitment(public_key: &str, content: impl Into<StartContent>) -> String {
|
||||||
let content = content.into().to_canonical_json();
|
let content = content.into().canonical_json();
|
||||||
|
|
||||||
encode(
|
encode(
|
||||||
Sha256::new()
|
Sha256::new()
|
||||||
|
|
|
@ -53,6 +53,7 @@ use self::event_enums::CancelContent;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// A result of a verification flow.
|
/// A result of a verification flow.
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum VerificationResult {
|
pub enum VerificationResult {
|
||||||
/// The verification succeeded, nothing needs to be done.
|
/// The verification succeeded, nothing needs to be done.
|
||||||
Ok,
|
Ok,
|
||||||
|
|
|
@ -86,13 +86,6 @@ impl FlowId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
|
||||||
match self {
|
|
||||||
FlowId::InRoom(_, r) => r.to_string(),
|
|
||||||
FlowId::ToDevice(t) => t.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
FlowId::InRoom(_, r) => r.as_str(),
|
FlowId::InRoom(_, r) => r.as_str(),
|
||||||
|
@ -403,8 +396,8 @@ 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(_) => StartContent::ToDevice(StartToDeviceEventContent {
|
FlowId::ToDevice(s) => StartContent::ToDevice(StartToDeviceEventContent {
|
||||||
transaction_id: self.verification_flow_id.to_string(),
|
transaction_id: s.to_string(),
|
||||||
from_device: self.device_id().into(),
|
from_device: self.device_id().into(),
|
||||||
method: StartMethod::MSasV1(
|
method: StartMethod::MSasV1(
|
||||||
MSasV1Content::new(self.state.protocol_definitions.clone())
|
MSasV1Content::new(self.state.protocol_definitions.clone())
|
||||||
|
@ -590,8 +583,8 @@ impl SasState<Started> {
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.verification_flow_id.as_ref() {
|
match self.verification_flow_id.as_ref() {
|
||||||
FlowId::ToDevice(_) => AcceptToDeviceEventContent {
|
FlowId::ToDevice(s) => AcceptToDeviceEventContent {
|
||||||
transaction_id: self.verification_flow_id.to_string(),
|
transaction_id: s.to_string(),
|
||||||
method,
|
method,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -732,12 +725,12 @@ impl SasState<KeyReceived> {
|
||||||
/// if we_started is false.
|
/// if we_started is false.
|
||||||
pub fn as_content(&self) -> KeyContent {
|
pub fn as_content(&self) -> KeyContent {
|
||||||
match &*self.verification_flow_id {
|
match &*self.verification_flow_id {
|
||||||
FlowId::ToDevice(s) => KeyContent::ToDevice(KeyToDeviceEventContent {
|
FlowId::ToDevice(s) => KeyToDeviceEventContent {
|
||||||
transaction_id: s.to_string(),
|
transaction_id: s.to_string(),
|
||||||
key: self.inner.lock().unwrap().public_key(),
|
key: self.inner.lock().unwrap().public_key(),
|
||||||
})
|
}
|
||||||
.into(),
|
.into(),
|
||||||
FlowId::InRoom(r, e) => KeyContent::Room(
|
FlowId::InRoom(r, e) => (
|
||||||
r.clone(),
|
r.clone(),
|
||||||
KeyEventContent {
|
KeyEventContent {
|
||||||
key: self.inner.lock().unwrap().public_key(),
|
key: self.inner.lock().unwrap().public_key(),
|
||||||
|
|
Loading…
Reference in New Issue