Skip to content

Commit 35e6629

Browse files
committed
Apply lints
1 parent 1095234 commit 35e6629

10 files changed

Lines changed: 54 additions & 51 deletions

File tree

creds-lib/src/model.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum CredentialRequest {
2222

2323
#[derive(Clone, Debug)]
2424
pub enum CredentialResponse {
25-
CreatePublicKeyCredentialResponse(MakeCredentialResponseInternal),
26-
GetPublicKeyCredentialResponse(GetAssertionResponseInternal),
25+
CreatePublicKeyCredentialResponse(Box<MakeCredentialResponseInternal>),
26+
GetPublicKeyCredentialResponse(Box<GetAssertionResponseInternal>),
2727
}
2828

2929
impl CredentialResponse {
@@ -32,17 +32,18 @@ impl CredentialResponse {
3232
transports: &[&str],
3333
modality: &str,
3434
) -> CredentialResponse {
35-
CredentialResponse::CreatePublicKeyCredentialResponse(MakeCredentialResponseInternal::new(
36-
response.clone(),
37-
transports.iter().map(|s| s.to_string()).collect(),
38-
modality.to_string(),
35+
CredentialResponse::CreatePublicKeyCredentialResponse(Box::new(
36+
MakeCredentialResponseInternal::new(
37+
response.clone(),
38+
transports.iter().map(|s| s.to_string()).collect(),
39+
modality.to_string(),
40+
),
3941
))
4042
}
4143

4244
pub fn from_get_assertion(assertion: &Assertion, modality: &str) -> CredentialResponse {
43-
CredentialResponse::GetPublicKeyCredentialResponse(GetAssertionResponseInternal::new(
44-
assertion.clone(),
45-
modality.to_string(),
45+
CredentialResponse::GetPublicKeyCredentialResponse(Box::new(
46+
GetAssertionResponseInternal::new(assertion.clone(), modality.to_string()),
4647
))
4748
}
4849
}

creds-ui/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl FlowController for DbusCredentialClient {
8181
.initiate_event_stream()
8282
.await
8383
.map_err(|err| tracing::error!("Failed to initialize event stream: {err}"))
84-
.and_then(|_| Ok(stream))
84+
.map(|_| stream)
8585
}
8686

8787
async fn enter_client_pin(&mut self, pin: String) -> std::result::Result<(), ()> {

creds-ui/src/gui/view_model/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl<F: FlowController + Send> ViewModel<F> {
6161

6262
async fn update_title(&mut self) {
6363
self.title = match self.operation {
64-
Operation::Create { .. } => "Create new credential",
65-
Operation::Get { .. } => "Use a credential",
64+
Operation::Create => "Create new credential",
65+
Operation::Get => "Use a credential",
6666
}
6767
.to_string();
6868
self.tx_update
@@ -158,12 +158,13 @@ impl<F: FlowController + Send> ViewModel<F> {
158158
cred_id, self.selected_device
159159
);
160160

161-
if let Err(_) = self
161+
if self
162162
.flow_controller
163163
.lock()
164164
.await
165165
.select_credential(cred_id)
166166
.await
167+
.is_err()
167168
{
168169
let error_msg = "Failed to select credential from device.";
169170
tracing::error!(error_msg);

credsd/src/credential_service/hybrid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl HybridHandler for InternalHybridHandler {
124124
}
125125
};
126126
let terminal_state = match response {
127-
Ok(auth_response) => HybridStateInternal::Completed(auth_response),
127+
Ok(auth_response) => HybridStateInternal::Completed(Box::new(auth_response)),
128128
Err(_) => HybridStateInternal::Failed,
129129
};
130130
if let Err(err) = tx.send(terminal_state).await {
@@ -154,7 +154,7 @@ pub(super) enum HybridStateInternal {
154154
Connected,
155155

156156
/// Authenticator data
157-
Completed(AuthenticatorResponse),
157+
Completed(Box<AuthenticatorResponse>),
158158

159159
Failed,
160160
// TODO(cancellation)
@@ -341,7 +341,7 @@ pub(super) mod test {
341341
states: vec![
342342
HybridStateInternal::Init(qr_code),
343343
HybridStateInternal::Connecting,
344-
HybridStateInternal::Completed(response.into()),
344+
HybridStateInternal::Completed(Box::new(response.into())),
345345
],
346346
}
347347
}

credsd/src/credential_service/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use libwebauthn::{
1515
self,
1616
ops::webauthn::{GetAssertionResponse, MakeCredentialResponse},
1717
};
18-
use tokio::sync::{oneshot::Sender, Mutex as AsyncMutex};
18+
use tokio::sync::oneshot::Sender;
1919

2020
use creds_lib::{
2121
model::{
@@ -133,7 +133,7 @@ impl<H: HybridHandler + Debug, U: UsbHandler + Debug, UC: UiController + Debug>
133133
) -> Pin<Box<dyn Stream<Item = HybridState> + Send + 'static>> {
134134
let guard = self.ctx.lock().unwrap();
135135
if let Some((ref cred_request, _)) = *guard {
136-
let stream = self.hybrid_handler.start(&cred_request);
136+
let stream = self.hybrid_handler.start(cred_request);
137137
let ctx = self.ctx.clone();
138138
Box::pin(HybridStateStream { inner: stream, ctx })
139139
} else {
@@ -147,7 +147,7 @@ impl<H: HybridHandler + Debug, U: UsbHandler + Debug, UC: UiController + Debug>
147147
pub fn get_usb_credential(&self) -> Pin<Box<dyn Stream<Item = UsbState> + Send + 'static>> {
148148
let guard = self.ctx.lock().unwrap();
149149
if let Some((ref cred_request, _)) = *guard {
150-
let stream = self.usb_handler.start(&cred_request);
150+
let stream = self.usb_handler.start(cred_request);
151151
let ctx = self.ctx.clone();
152152
Box::pin(UsbStateStream { inner: stream, ctx })
153153
} else {
@@ -179,7 +179,7 @@ where
179179
Poll::Pending => Poll::Pending,
180180
Poll::Ready(Some(HybridEvent { state })) => {
181181
if let HybridStateInternal::Completed(hybrid_response) = &state {
182-
let response = match hybrid_response {
182+
let response = match &**hybrid_response {
183183
AuthenticatorResponse::CredentialCreated(make_credential_response) => {
184184
CredentialResponse::from_make_credential(
185185
make_credential_response,
@@ -250,13 +250,13 @@ fn complete_request(ctx: &Mutex<Option<RequestContext>>, response: CredentialRes
250250

251251
#[derive(Debug, Clone)]
252252
enum AuthenticatorResponse {
253-
CredentialCreated(MakeCredentialResponse),
253+
CredentialCreated(Box<MakeCredentialResponse>),
254254
CredentialsAsserted(GetAssertionResponse),
255255
}
256256

257257
impl From<MakeCredentialResponse> for AuthenticatorResponse {
258258
fn from(value: MakeCredentialResponse) -> Self {
259-
Self::CredentialCreated(value)
259+
Self::CredentialCreated(Box::new(value))
260260
}
261261
}
262262

@@ -307,7 +307,7 @@ mod test {
307307
let hybrid_handler = DummyHybridHandler::new(vec![
308308
HybridStateInternal::Init(qr_code),
309309
HybridStateInternal::Connecting,
310-
HybridStateInternal::Completed(authenticator_response),
310+
HybridStateInternal::Completed(Box::new(authenticator_response)),
311311
]);
312312
let usb_handler = InProcessUsbHandler {};
313313
let (ui_server, ui_client) = DummyUiServer::new(Vec::new());

credsd/src/credential_service/usb.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ impl InProcessUsbHandler {
165165
.cloned();
166166
match assertion {
167167
Some(assertion) => Ok(UsbStateInternal::Completed(
168-
CredentialResponse::GetPublicKeyCredentialResponse(
168+
CredentialResponse::GetPublicKeyCredentialResponse(Box::new(
169169
GetAssertionResponseInternal::new(
170170
assertion,
171171
"cross-platform".to_string(),
172172
),
173-
),
173+
)),
174174
)),
175175
None => Err(Error::NoCredentials),
176176
}
@@ -201,7 +201,7 @@ impl InProcessUsbHandler {
201201
Ok(UsbStateInternal::NeedsUserVerification { attempts_left })
202202
}
203203
Ok(UsbUvMessage::NeedsUserPresence) => Ok(UsbStateInternal::NeedsUserPresence),
204-
Ok(UsbUvMessage::ReceivedCredentials(response)) => match response {
204+
Ok(UsbUvMessage::ReceivedCredentials(response)) => match *response {
205205
AuthenticatorResponse::CredentialCreated(make_credential_response) => Ok(
206206
UsbStateInternal::Completed(CredentialResponse::from_make_credential(
207207
&make_credential_response,
@@ -307,12 +307,16 @@ async fn handle_events(
307307
channel
308308
.webauthn_make_credential(make_cred_request)
309309
.await
310-
.map(|response| UsbUvMessage::ReceivedCredentials(response.into()))
310+
.map(|response| {
311+
UsbUvMessage::ReceivedCredentials(Box::new(response.into()))
312+
})
311313
}
312314
CredentialRequest::GetPublicKeyCredentialRequest(get_cred_request) => channel
313315
.webauthn_get_assertion(get_cred_request)
314316
.await
315-
.map(|response| UsbUvMessage::ReceivedCredentials(response.into())),
317+
.map(|response| {
318+
UsbUvMessage::ReceivedCredentials(Box::new(response.into()))
319+
}),
316320
};
317321
match response {
318322
Ok(response) => {
@@ -613,5 +617,5 @@ enum UsbUvMessage {
613617
attempts_left: Option<u32>,
614618
},
615619
NeedsUserPresence,
616-
ReceivedCredentials(AuthenticatorResponse),
620+
ReceivedCredentials(Box<AuthenticatorResponse>),
617621
}

credsd/src/dbus/flow_control.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use crate::credential_service::{
2929
usb::UsbHandler,
3030
CredentialService, UiController, UsbState,
3131
};
32-
pub const SERVICE_PATH: &'static str = "/xyz/iinuwa/credentials/FlowControl";
33-
pub const SERVICE_NAME: &'static str = "xyz.iinuwa.credentials.FlowControl";
32+
pub const SERVICE_PATH: &str = "/xyz/iinuwa/credentials/FlowControl";
33+
pub const SERVICE_NAME: &str = "xyz.iinuwa.credentials.FlowControl";
3434

3535
pub async fn start_flow_control_service<
3636
H: HybridHandler + Debug + Send + Sync + 'static,
@@ -157,7 +157,7 @@ where
157157
tracing::error!("Failed to serialize state update: {err}");
158158
break;
159159
}
160-
Ok(event) => match send_state_update(&emitter, &signal_state, event).await {
160+
Ok(event) => match send_state_update(emitter, &signal_state, event).await {
161161
Ok(_) => {}
162162
Err(err) => {
163163
tracing::error!("Failed to send state update to UI: {err}");
@@ -207,7 +207,7 @@ where
207207
tracing::error!("Failed to serialize state update: {err}");
208208
break;
209209
}
210-
Ok(event) => match send_state_update(&emitter, &signal_state, event).await {
210+
Ok(event) => match send_state_update(emitter, &signal_state, event).await {
211211
Ok(_) => {}
212212
Err(err) => {
213213
tracing::error!("Failed to send state update to UI: {err}");

credsd/src/dbus/gateway.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::dbus::{
1919
CredentialRequestController,
2020
};
2121

22-
pub const SERVICE_NAME: &'static str = "xyz.iinuwa.credentials.Credentials";
23-
pub const SERVICE_PATH: &'static str = "/xyz/iinuwa/credentials/Credentials";
22+
pub const SERVICE_NAME: &str = "xyz.iinuwa.credentials.Credentials";
23+
pub const SERVICE_PATH: &str = "/xyz/iinuwa/credentials/Credentials";
2424

2525
pub async fn start_gateway<C: CredentialRequestController + Send + Sync + 'static>(
2626
controller: C,
@@ -51,12 +51,10 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
5151
&self,
5252
request: CreateCredentialRequest,
5353
) -> Result<CreateCredentialResponse, Error> {
54-
let (_origin, is_same_origin, _top_origin) = check_origin(
55-
request.origin.as_ref().map(|s| s.as_str()),
56-
request.is_same_origin,
57-
)
58-
.await
59-
.map_err(Error::from)?;
54+
let (_origin, is_same_origin, _top_origin) =
55+
check_origin(request.origin.as_deref(), request.is_same_origin)
56+
.await
57+
.map_err(Error::from)?;
6058
if let ("publicKey", Some(_)) = (request.r#type.as_ref(), &request.public_key) {
6159
if !is_same_origin {
6260
// TODO: Once we modify the models to convey the top-origin in cross origin requests to the UI, we can remove this error message.
@@ -107,12 +105,10 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
107105
&self,
108106
request: GetCredentialRequest,
109107
) -> Result<GetCredentialResponse, Error> {
110-
let (_origin, is_same_origin, _top_origin) = check_origin(
111-
request.origin.as_ref().map(|s| s.as_str()),
112-
request.is_same_origin,
113-
)
114-
.await
115-
.map_err(Error::from)?;
108+
let (_origin, is_same_origin, _top_origin) =
109+
check_origin(request.origin.as_deref(), request.is_same_origin)
110+
.await
111+
.map_err(Error::from)?;
116112
if let ("publicKey", Some(_)) = (request.r#type.as_ref(), &request.public_key) {
117113
if !is_same_origin {
118114
// TODO: Once we modify the models to convey the top-origin in cross origin requests to the UI, we can remove this error message.
@@ -199,11 +195,12 @@ async fn check_origin(
199195
origin.clone()
200196
} else {
201197
tracing::warn!("Client attempted to issue cross-origin request for credentials, which are not supported by this platform.");
202-
return Err(WebAuthnError::NotAllowedError.into());
198+
return Err(WebAuthnError::NotAllowedError);
203199
};
204200
Ok((origin, true, top_origin))
205201
}
206202

203+
#[allow(clippy::enum_variant_names)]
207204
#[derive(DBusError, Debug)]
208205
#[zbus(prefix = "xyz.iinuwa.credentials")]
209206
enum Error {

credsd/src/dbus/ui_control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! These methods are called by the flow controller to launch the trusted UI.
22
3-
use std::{error::Error, future::Future};
3+
use std::error::Error;
44

55
use zbus::{fdo, proxy, Connection};
66

credsd/src/webauthn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ pub fn format_client_data_json(
685685
is_cross_origin: bool,
686686
) -> String {
687687
let op_str = match op {
688-
Operation::Create { .. } => "webauthn.create",
689-
Operation::Get { .. } => "webauthn.get",
688+
Operation::Create => "webauthn.create",
689+
Operation::Get => "webauthn.get",
690690
};
691691
let cross_origin_str = if is_cross_origin { "true" } else { "false" };
692692
format!("{{\"type\":\"{op_str}\",\"challenge\":\"{challenge}\",\"origin\":\"{origin}\",\"crossOrigin\":{cross_origin_str}}}")

0 commit comments

Comments
 (0)