Skip to content

Commit 6f80c1b

Browse files
authored
Merge pull request #19 from linux-credentials/add-lints
Add lints
2 parents 11f7866 + 32b042a commit 6f80c1b

10 files changed

Lines changed: 141 additions & 76 deletions

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ jobs:
3636
# Probably has to do with forking the test processes.
3737
run: meson test --interactive
3838
working-directory: build/
39+
- name: Check clippy recommendations
40+
run: env CARGO_HOME=build/cargo-home cargo clippy --manifest-path xyz-iinuwa-credential-manager-portal-gtk/Cargo.toml --target-dir build/xyz-iinuwa-credential-manager-portal-gtk/src
41+
- name: Check formatting
42+
run: cargo fmt --check
43+
working-directory: xyz-iinuwa-credential-manager-portal-gtk

xyz-iinuwa-credential-manager-portal-gtk/src/application.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ mod imp {
5757
vm2.clone().connect_completed_notify(move |vm| {
5858
if vm.completed() {
5959
glib::spawn_future_local(clone!(
60-
#[weak] window2,
60+
#[weak]
61+
window2,
6162
async move {
6263
// Wait to show confirmation before closing.
6364
async_std::task::sleep(Duration::from_millis(500)).await;
64-
gtk::prelude::WidgetExt::activate_action(&window2, "window.close", None).unwrap()
65+
gtk::prelude::WidgetExt::activate_action(&window2, "window.close", None)
66+
.unwrap()
6567
}
6668
));
6769
}

xyz-iinuwa-credential-manager-portal-gtk/src/cbor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ where
7575
Ok(())
7676
}
7777

78-
7978
pub fn write_text(&mut self, text: &str) -> Result<(), Error> {
8079
let data = text.as_bytes();
8180
self.write_cbor_value(

xyz-iinuwa-credential-manager-portal-gtk/src/cose.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
use libwebauthn::proto::ctap2::Ctap2COSEAlgorithmIdentifier;
32
use ring::{
4-
rand::SystemRandom, signature::{
5-
EcdsaKeyPair, Ed25519KeyPair, KeyPair,
6-
RsaKeyPair, ECDSA_P256_SHA256_ASN1_SIGNING,
7-
}
3+
rand::SystemRandom,
4+
signature::{
5+
EcdsaKeyPair, Ed25519KeyPair, KeyPair, RsaKeyPair, ECDSA_P256_SHA256_ASN1_SIGNING,
6+
},
87
};
98
use tracing::debug;
109

@@ -48,9 +47,18 @@ impl CoseKeyParameters {
4847
impl From<CoseKeyType> for CoseKeyParameters {
4948
fn from(value: CoseKeyType) -> Self {
5049
match value {
51-
CoseKeyType::ES256_P256 => CoseKeyParameters { alg: CoseKeyAlgorithmIdentifier::ES256, crv: Some(CoseEllipticCurveIdentifier::P256) },
52-
CoseKeyType::EDDSA_ED25519 => CoseKeyParameters { alg: CoseKeyAlgorithmIdentifier::EdDSA, crv: Some(CoseEllipticCurveIdentifier::Ed25519) },
53-
CoseKeyType::RS256 => CoseKeyParameters { alg: CoseKeyAlgorithmIdentifier::RS256, crv: None, },
50+
CoseKeyType::ES256_P256 => CoseKeyParameters {
51+
alg: CoseKeyAlgorithmIdentifier::ES256,
52+
crv: Some(CoseEllipticCurveIdentifier::P256),
53+
},
54+
CoseKeyType::EDDSA_ED25519 => CoseKeyParameters {
55+
alg: CoseKeyAlgorithmIdentifier::EdDSA,
56+
crv: Some(CoseEllipticCurveIdentifier::Ed25519),
57+
},
58+
CoseKeyType::RS256 => CoseKeyParameters {
59+
alg: CoseKeyAlgorithmIdentifier::RS256,
60+
crv: None,
61+
},
5462
}
5563
}
5664
}
@@ -126,10 +134,7 @@ pub enum Error {
126134
Unsupported,
127135
}
128136

129-
pub(super) fn encode_pkcs8_key(
130-
key_type: CoseKeyType,
131-
pkcs8_key: &[u8],
132-
) -> Result<Vec<u8>, Error> {
137+
pub(super) fn encode_pkcs8_key(key_type: CoseKeyType, pkcs8_key: &[u8]) -> Result<Vec<u8>, Error> {
133138
match key_type {
134139
CoseKeyType::ES256_P256 => {
135140
let key_pair = EcdsaKeyPair::from_pkcs8(
@@ -194,7 +199,7 @@ pub(super) fn encode_pkcs8_key(
194199
/// returns CTAP2-serialized public key and algorithm
195200
pub(crate) fn encode_cose_key(public_key: &cosey::PublicKey) -> Result<Vec<u8>, Error> {
196201
match public_key {
197-
cosey::PublicKey::P256Key(p256_key) => {
202+
cosey::PublicKey::P256Key(p256_key) => {
198203
let mut cose_key: Vec<u8> = Vec::new();
199204
cose_key.push(0b101_00101); // map with 5 items
200205
cose_key.extend([0b000_00001, 0b000_00010]); // kty (1): EC2 (2)
@@ -205,7 +210,7 @@ pub(crate) fn encode_cose_key(public_key: &cosey::PublicKey) -> Result<Vec<u8>,
205210
cose_key.extend([0b001_00010, 0b010_11000, 0b0010_0000]); // y (-3): <32-byte string>
206211
cose_key.extend(p256_key.y.clone());
207212
Ok(cose_key)
208-
},
213+
}
209214
cosey::PublicKey::Ed25519Key(ed25519_key) => {
210215
// TODO: Check this
211216
let mut cose_key: Vec<u8> = Vec::new();
@@ -216,7 +221,7 @@ pub(crate) fn encode_cose_key(public_key: &cosey::PublicKey) -> Result<Vec<u8>,
216221
cose_key.extend([0b001_00001, 0b010_11000, 0b0010_0000]); // x (-2): <32-byte string>
217222
cose_key.extend(ed25519_key.x.clone());
218223
Ok(cose_key)
219-
},
224+
}
220225

221226
_ => {
222227
debug!("Cannot serialize unknown key type {:?}", public_key);

xyz-iinuwa-credential-manager-portal-gtk/src/credential_service/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ impl CredentialService {
402402
}
403403
}
404404

405-
406405
#[derive(Copy, Clone, Debug, Default, PartialEq)]
407406
pub enum UsbState {
408407
/// Not polling for FIDO USB device.

xyz-iinuwa-credential-manager-portal-gtk/src/serde/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ pub(crate) mod b64 {
44
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
55

66
pub(crate) fn serialize<S>(value: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
7-
where S: Serializer {
7+
where
8+
S: Serializer,
9+
{
810
let s = URL_SAFE_NO_PAD.encode(value);
911
String::serialize(&s, serializer)
1012
}
1113

1214
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
13-
where D: Deserializer<'de> {
15+
where
16+
D: Deserializer<'de>,
17+
{
1418
let s = String::deserialize(deserializer)?;
1519
URL_SAFE_NO_PAD.decode(s).map_err(de::Error::custom)
1620
}
@@ -22,7 +26,10 @@ pub(crate) mod duration {
2226
use serde::{Deserialize, Deserializer};
2327

2428
pub(crate) fn from_opt_ms<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
25-
where D: Deserializer<'de> {
26-
Option::<u32>::deserialize(deserializer).map(|ms_opt| ms_opt.map(|ms| Duration::from_millis(ms as u64)))
29+
where
30+
D: Deserializer<'de>,
31+
{
32+
Option::<u32>::deserialize(deserializer)
33+
.map(|ms_opt| ms_opt.map(|ms| Duration::from_millis(ms as u64)))
2734
}
28-
}
35+
}

xyz-iinuwa-credential-manager-portal-gtk/src/view_model/gtk/mod.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl ViewModel {
8989
self.imp().tx.replace(Some(tx));
9090
self.imp().rx.replace(Some(rx));
9191
glib::spawn_future_local(clone!(
92-
#[weak(rename_to = view_model)] self,
92+
#[weak(rename_to = view_model)]
93+
self,
9394
async move {
9495
loop {
9596
let rx = view_model.imp().rx.borrow();
@@ -99,36 +100,48 @@ impl ViewModel {
99100
// TODO: hack so I don't have to unset this in every event manually.
100101
view_model.set_usb_pin_entry_visible(false);
101102
match update {
102-
ViewUpdate::SetTitle(title) => { view_model.set_title(title) },
103-
ViewUpdate::SetDevices(devices) => { view_model.update_devices(&devices) },
104-
ViewUpdate::SetCredentials(credentials) => { view_model.update_credentials(&credentials) },
105-
ViewUpdate::SelectDevice(device) => { view_model.select_device(&device) },
106-
ViewUpdate::SelectCredential(cred_id) => { view_model.select_credential(cred_id) },
103+
ViewUpdate::SetTitle(title) => view_model.set_title(title),
104+
ViewUpdate::SetDevices(devices) => {
105+
view_model.update_devices(&devices)
106+
}
107+
ViewUpdate::SetCredentials(credentials) => {
108+
view_model.update_credentials(&credentials)
109+
}
110+
ViewUpdate::SelectDevice(device) => {
111+
view_model.select_device(&device)
112+
}
113+
ViewUpdate::SelectCredential(cred_id) => {
114+
view_model.select_credential(cred_id)
115+
}
107116
ViewUpdate::UsbNeedsPin { attempts_left } => {
108117
let prompt = match attempts_left {
109-
Some(1) => "Enter your PIN. 1 attempt remaining.".to_string(),
110-
Some(attempts_left) => format!("Enter your PIN. {attempts_left} attempts remaining."),
118+
Some(1) => {
119+
"Enter your PIN. 1 attempt remaining.".to_string()
120+
}
121+
Some(attempts_left) => format!(
122+
"Enter your PIN. {attempts_left} attempts remaining."
123+
),
111124
None => format!("Enter your PIN."),
112125
};
113126
view_model.set_prompt(prompt);
114127
view_model.set_usb_pin_entry_visible(true);
115-
},
128+
}
116129
ViewUpdate::UsbNeedsUserVerification { attempts_left } => {
117130
let prompt = match attempts_left {
118131
Some(1) => "Touch your device again. 1 attempt remaining.".to_string(),
119132
Some(attempts_left) => format!("Touch your device again. {attempts_left} attempts remaining."),
120133
None => format!("Touch your device."),
121134
};
122135
view_model.set_prompt(prompt);
123-
},
136+
}
124137
ViewUpdate::UsbNeedsUserPresence => {
125138
view_model.set_prompt("Touch your device");
126-
},
139+
}
127140
ViewUpdate::Completed => {
128141
view_model.set_completed(true);
129-
},
142+
}
130143
}
131-
},
144+
}
132145
Err(e) => {
133146
debug!("ViewModel event listener interrupted: {}", e);
134147
break;

xyz-iinuwa-credential-manager-portal-gtk/src/view_model/mod.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,16 @@ impl ViewModel {
232232
match prev_state {
233233
UsbState::Completed => break,
234234
UsbState::UserCancelled => break,
235-
_ => {},
235+
_ => {}
236236
};
237237
async_std::task::sleep(Duration::from_millis(50)).await;
238-
},
238+
}
239239
Err(err) => {
240240
// TODO: move to error page
241-
tracing::error!("There was an error trying to get credentials from USB: {}", err);
241+
tracing::error!(
242+
"There was an error trying to get credentials from USB: {}",
243+
err
244+
);
242245
break;
243246
}
244247
};
@@ -266,9 +269,11 @@ impl ViewModel {
266269
{
267270
if prev_state != current_state {
268271
println!("{:?}", current_state);
269-
tx.send(BackgroundEvent::InternalDeviceStateChanged(current_state.clone()))
270-
.await
271-
.unwrap();
272+
tx.send(BackgroundEvent::InternalDeviceStateChanged(
273+
current_state.clone(),
274+
))
275+
.await
276+
.unwrap();
272277
}
273278
prev_state = current_state;
274279
}
@@ -356,19 +361,25 @@ impl ViewModel {
356361
}
357362

358363
UsbState::NeedsPin { attempts_left } => {
359-
self.tx_update.send(ViewUpdate::UsbNeedsPin { attempts_left }).await.unwrap();
364+
self.tx_update
365+
.send(ViewUpdate::UsbNeedsPin { attempts_left })
366+
.await
367+
.unwrap();
360368
}
361369
UsbState::NeedsUserVerification { attempts_left } => {
362-
self.tx_update.send(ViewUpdate::UsbNeedsUserVerification { attempts_left }).await.unwrap();
370+
self.tx_update
371+
.send(ViewUpdate::UsbNeedsUserVerification { attempts_left })
372+
.await
373+
.unwrap();
363374
}
364-
UsbState::NeedsUserPresence => {
365-
self.tx_update.send(ViewUpdate::UsbNeedsUserPresence).await.unwrap();
375+
UsbState::NeedsUserPresence => {
376+
self.tx_update
377+
.send(ViewUpdate::UsbNeedsUserPresence)
378+
.await
379+
.unwrap();
366380
}
367381
UsbState::Completed => {
368-
self.credential_service
369-
.lock()
370-
.await
371-
.complete_auth();
382+
self.credential_service.lock().await.complete_auth();
372383
self.tx_update.send(ViewUpdate::Completed).await.unwrap();
373384
}
374385
_ => {}
@@ -381,10 +392,7 @@ impl ViewModel {
381392
// self.tx_update.send(ViewUpdate::InternalDeviceNeedsPin).await.unwrap();
382393
// },
383394
InternalDeviceState::Completed { device, cred_id } => {
384-
self.credential_service
385-
.lock()
386-
.await
387-
.complete_auth();
395+
self.credential_service.lock().await.complete_auth();
388396
self.tx_update.send(ViewUpdate::Completed).await.unwrap();
389397
}
390398
_ => {}
@@ -547,7 +555,6 @@ impl From<Transport> for String {
547555
}
548556
}
549557

550-
551558
impl Transport {
552559
fn as_str(&self) -> &'static str {
553560
match self {
@@ -571,10 +578,14 @@ pub enum UsbState {
571578
Waiting,
572579

573580
/// The device needs the PIN to be entered.
574-
NeedsPin { attempts_left: Option<u32> },
581+
NeedsPin {
582+
attempts_left: Option<u32>,
583+
},
575584

576585
/// The device needs on-device user verification to be entered.
577-
NeedsUserVerification { attempts_left: Option<u32> },
586+
NeedsUserVerification {
587+
attempts_left: Option<u32>,
588+
},
578589

579590
/// The device needs on-device user verification to be entered.
580591
NeedsUserPresence,
@@ -595,8 +606,12 @@ impl From<crate::credential_service::UsbState> for UsbState {
595606
crate::credential_service::UsbState::Idle => UsbState::NotListening,
596607
crate::credential_service::UsbState::Waiting => UsbState::Waiting,
597608
crate::credential_service::UsbState::Connected => UsbState::Connected,
598-
crate::credential_service::UsbState::NeedsPin { attempts_left }=> UsbState::NeedsPin { attempts_left },
599-
crate::credential_service::UsbState::NeedsUserVerification { attempts_left }=> UsbState::NeedsUserVerification { attempts_left },
609+
crate::credential_service::UsbState::NeedsPin { attempts_left } => {
610+
UsbState::NeedsPin { attempts_left }
611+
}
612+
crate::credential_service::UsbState::NeedsUserVerification { attempts_left } => {
613+
UsbState::NeedsUserVerification { attempts_left }
614+
}
600615
crate::credential_service::UsbState::NeedsUserPresence => UsbState::NeedsUserPresence,
601616
crate::credential_service::UsbState::Completed => UsbState::Completed,
602617
crate::credential_service::UsbState::UserCancelled => UsbState::UserCancelled,

0 commit comments

Comments
 (0)