crypto: Fix a bunch of clippy warnings.

master
Damir Jelić 2020-12-18 13:50:02 +01:00
parent 897c6abe92
commit 1fd8c2052e
8 changed files with 48 additions and 57 deletions

View File

@ -1165,7 +1165,7 @@ impl Client {
request: &RoomMessageRequest,
) -> Result<send_message_event::Response> {
let content = request.content.clone();
let txn_id = request.txn_id.into();
let txn_id = request.txn_id;
let room_id = &request.room_id;
self.room_send(&room_id, content, Some(txn_id)).await

View File

@ -743,8 +743,8 @@ impl OlmMachine {
}
}
async fn handle_verification_event(&self, mut event: &mut AnyToDeviceEvent) {
if let Err(e) = self.verification_machine.receive_event(&mut event).await {
async fn handle_verification_event(&self, event: &AnyToDeviceEvent) {
if let Err(e) = self.verification_machine.receive_event(&event).await {
error!("Error handling a verification event: {:?}", e);
}
}
@ -879,7 +879,7 @@ impl OlmMachine {
| AnyToDeviceEvent::KeyVerificationMac(..)
| AnyToDeviceEvent::KeyVerificationRequest(..)
| AnyToDeviceEvent::KeyVerificationStart(..) => {
self.handle_verification_event(&mut event).await;
self.handle_verification_event(&event).await;
}
_ => continue,
}
@ -1826,34 +1826,34 @@ pub(crate) mod test {
let (alice_sas, request) = bob_device.start_verification().await.unwrap();
let mut event = request_to_event(alice.user_id(), &request.into());
bob.handle_verification_event(&mut event).await;
let event = request_to_event(alice.user_id(), &request.into());
bob.handle_verification_event(&event).await;
let bob_sas = bob.get_verification(alice_sas.flow_id().as_str()).unwrap();
assert!(alice_sas.emoji().is_none());
assert!(bob_sas.emoji().is_none());
let mut event = bob_sas
let event = bob_sas
.accept()
.map(|r| request_to_event(bob.user_id(), &r))
.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()
.first()
.map(|r| outgoing_request_to_event(alice.user_id(), r))
.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()
.first()
.map(|r| outgoing_request_to_event(bob.user_id(), r))
.unwrap();
alice.handle_verification_event(&mut event).await;
alice.handle_verification_event(&event).await;
assert!(alice_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.decimals(), bob_sas.decimals());
let mut event = bob_sas
let event = bob_sas
.confirm()
.await
.unwrap()
.0
.map(|r| request_to_event(bob.user_id(), &r))
.unwrap();
alice.handle_verification_event(&mut event).await;
alice.handle_verification_event(&event).await;
assert!(!alice_sas.is_done());
assert!(!bob_sas.is_done());
let mut event = alice_sas
let event = alice_sas
.confirm()
.await
.unwrap()
@ -1891,7 +1891,7 @@ pub(crate) mod test {
.unwrap();
assert!(!alice_device.is_trusted());
bob.handle_verification_event(&mut event).await;
bob.handle_verification_event(&event).await;
assert!(bob_sas.is_done());
assert!(alice_device.is_trusted());
}

View File

@ -96,7 +96,7 @@ impl VerificationMachine {
let request = content_to_request(device.user_id(), device.device_id(), c);
self.verifications
.insert(sas.flow_id().to_string(), sas.clone());
.insert(sas.flow_id().as_str().to_owned(), sas.clone());
request.into()
}
@ -152,7 +152,7 @@ impl VerificationMachine {
request: Arc::new(
RoomMessageRequest {
room_id: r,
txn_id: request_id.clone(),
txn_id: request_id,
content: c,
}
.into(),
@ -512,7 +512,7 @@ mod test {
);
machine
.receive_event(&mut wrap_any_to_device_content(
.receive_event(&wrap_any_to_device_content(
bob_sas.user_id(),
start_content.into(),
))
@ -536,18 +536,18 @@ mod test {
let alice = alice_machine.get_sas(bob.flow_id().as_str()).unwrap();
let mut event = alice
let event = alice
.accept()
.map(|c| wrap_any_to_device_content(alice.user_id(), get_content_from_request(&c)))
.unwrap();
let mut event = bob
.receive_event(&mut event)
let event = bob
.receive_event(&event)
.map(|c| wrap_any_to_device_content(bob.user_id(), c))
.unwrap();
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());
let request = alice_machine
@ -564,29 +564,29 @@ mod test {
panic!("Invalid request type");
};
let mut event =
let event =
wrap_any_to_device_content(alice.user_id(), get_content_from_request(&r.into()));
drop(request);
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!(bob.emoji().is_some());
assert_eq!(alice.emoji(), bob.emoji());
let mut event = wrap_any_to_device_content(
let event = wrap_any_to_device_content(
alice.user_id(),
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(),
get_content_from_request(&bob.confirm().await.unwrap().0.unwrap()),
);
alice.receive_event(&mut event);
alice.receive_event(&event);
assert!(alice.is_done());
assert!(bob.is_done());

View File

@ -86,13 +86,13 @@ impl VerificationRequest {
}
pub(crate) fn into_started_sas(
&self,
self,
event: &SyncMessageEvent<StartEventContent>,
device: ReadOnlyDevice,
user_identity: Option<UserIdentities>,
) -> Result<Sas, OutgoingContent> {
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()),
self.store.clone(),
self.account.clone(),
@ -129,7 +129,7 @@ impl InnerRequest {
}
fn into_started_sas(
&mut self,
self,
event: &MessageEvent<StartEventContent>,
store: Arc<Box<dyn CryptoStore>>,
account: ReadOnlyAccount,
@ -193,8 +193,7 @@ impl RequestState<Created> {
state: Sent {
methods: SUPPORTED_METHODS.to_vec(),
flow_id: response.event_id.clone(),
}
.into(),
},
}
}
}
@ -219,9 +218,8 @@ impl RequestState<Sent> {
state: Ready {
methods: content.methods.to_owned(),
other_device_id: content.from_device.clone(),
flow_id: self.state.flow_id.clone(),
}
.into(),
flow_id: self.state.flow_id,
},
}
}
}
@ -256,8 +254,7 @@ impl RequestState<Requested> {
methods: content.methods.clone(),
flow_id: event_id.clone(),
other_device_id: content.from_device.clone(),
}
.into(),
},
}
}
@ -300,7 +297,7 @@ struct Ready {
impl RequestState<Ready> {
fn into_started_sas(
&self,
self,
event: &MessageEvent<StartEventContent>,
store: Arc<Box<dyn CryptoStore>>,
account: ReadOnlyAccount,

View File

@ -55,7 +55,7 @@ impl StartContent {
}
}
pub fn to_canonical_json(self) -> CanonicalJsonValue {
pub fn canonical_json(self) -> CanonicalJsonValue {
let content = match self {
StartContent::ToDevice(c) => serde_json::to_value(c),
StartContent::Room(_, c) => serde_json::to_value(c),

View File

@ -62,7 +62,7 @@ pub struct SasIds {
/// * `content` - The `m.key.verification.start` event content that started the
/// interactive verification process.
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(
Sha256::new()

View File

@ -53,6 +53,7 @@ use self::event_enums::CancelContent;
#[derive(Debug)]
/// A result of a verification flow.
#[allow(clippy::large_enum_variant)]
pub enum VerificationResult {
/// The verification succeeded, nothing needs to be done.
Ok,

View File

@ -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 {
match self {
FlowId::InRoom(_, r) => r.as_str(),
@ -403,8 +396,8 @@ impl SasState<Created> {
pub fn as_content(&self) -> StartContent {
match self.verification_flow_id.as_ref() {
FlowId::ToDevice(_) => StartContent::ToDevice(StartToDeviceEventContent {
transaction_id: self.verification_flow_id.to_string(),
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())
@ -590,8 +583,8 @@ impl SasState<Started> {
);
match self.verification_flow_id.as_ref() {
FlowId::ToDevice(_) => AcceptToDeviceEventContent {
transaction_id: self.verification_flow_id.to_string(),
FlowId::ToDevice(s) => AcceptToDeviceEventContent {
transaction_id: s.to_string(),
method,
}
.into(),
@ -732,12 +725,12 @@ impl SasState<KeyReceived> {
/// if we_started is false.
pub fn as_content(&self) -> KeyContent {
match &*self.verification_flow_id {
FlowId::ToDevice(s) => KeyContent::ToDevice(KeyToDeviceEventContent {
FlowId::ToDevice(s) => KeyToDeviceEventContent {
transaction_id: s.to_string(),
key: self.inner.lock().unwrap().public_key(),
})
}
.into(),
FlowId::InRoom(r, e) => KeyContent::Room(
FlowId::InRoom(r, e) => (
r.clone(),
KeyEventContent {
key: self.inner.lock().unwrap().public_key(),