From 4310cc0f9a61a45c890c7eca5050f4441313bb53 Mon Sep 17 00:00:00 2001 From: "Tony Arcieri (iqlusion)" Date: Sat, 12 Nov 2022 14:15:42 -0700 Subject: [PATCH] Fix build and clippy warnings (#433) --- .github/workflows/ci.yml | 2 +- cli/src/terminal.rs | 6 ++---- src/certificate.rs | 2 +- src/mgm.rs | 2 +- src/piv.rs | 8 ++++---- src/policy.rs | 4 ++-- src/transaction.rs | 8 ++++---- src/yubikey.rs | 8 ++++---- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48ae0fc..97006c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.60.0 # MSRV + toolchain: 1.65.0 components: clippy override: true - run: sudo apt-get install libpcsclite-dev diff --git a/cli/src/terminal.rs b/cli/src/terminal.rs index bda7f34..db7114d 100644 --- a/cli/src/terminal.rs +++ b/cli/src/terminal.rs @@ -140,14 +140,12 @@ impl Status { /// Print the given message to stdout pub fn print_stdout(self, msg: impl AsRef) { - self.print(&*STDOUT, msg) - .expect("error printing to stdout!") + self.print(&STDOUT, msg).expect("error printing to stdout!") } /// Print the given message to stderr pub fn print_stderr(self, msg: impl AsRef) { - self.print(&*STDERR, msg) - .expect("error printing to stderr!") + self.print(&STDERR, msg).expect("error printing to stderr!") } /// Print the given message diff --git a/src/certificate.rs b/src/certificate.rs index 5762707..b7b36d3 100644 --- a/src/certificate.rs +++ b/src/certificate.rs @@ -97,7 +97,7 @@ impl Serial { } /// Information about how a [`Certificate`] is stored within a YubiKey. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum CertInfo { /// The certificate is uncompressed. Uncompressed, diff --git a/src/mgm.rs b/src/mgm.rs index c5ac1ec..b1a9c14 100644 --- a/src/mgm.rs +++ b/src/mgm.rs @@ -404,7 +404,7 @@ fn is_weak_key(key: &[u8; DES_LEN_3DES]) -> bool { c = (c & 0x0F) + ((c >> 4) & 0x0F); // if count is even, set low key bit to 1, otherwise 0 - tmp[i] = (key[i] & 0xFE) | (if c & 0x01 == 0x01 { 0x00 } else { 0x01 }); + tmp[i] = (key[i] & 0xFE) | u8::from(c & 0x01 != 0x01); } // check odd parity key against table by DES key block diff --git a/src/piv.rs b/src/piv.rs index c839c4e..70c35ac 100644 --- a/src/piv.rs +++ b/src/piv.rs @@ -143,7 +143,7 @@ impl TryFrom for SlotId { 0xf9 => Ok(SlotId::Attestation), _ => RetiredSlotId::try_from(value) .map(SlotId::Retired) - .or(ManagementSlotId::try_from(value).map(SlotId::Management)), + .or_else(|_| ManagementSlotId::try_from(value).map(SlotId::Management)), } } } @@ -185,7 +185,7 @@ impl FromStr for SlotId { _ => s .parse() .map(SlotId::Management) - .or(s.parse().map(SlotId::Retired)), + .or_else(|_| s.parse().map(SlotId::Retired)), } } } @@ -354,7 +354,7 @@ impl RetiredSlotId { /// Management slot IDs. #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Ord, PartialOrd)] pub enum ManagementSlotId { PIN, PUK, @@ -670,7 +670,7 @@ pub fn generate( } } - let value = &response.data()[..]; + let value = response.data(); read_public_key(algorithm, value, true) } diff --git a/src/policy.rs b/src/policy.rs index 27d7462..de39cd9 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -6,7 +6,7 @@ use crate::{serialization::Tlv, Error, Result}; /// given slot. /// /// This policy must be set when keys are generated or imported, and cannot be changed later. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum PinPolicy { /// Use the default PIN policy for the slot. See the slot's documentation for details. Default, @@ -64,7 +64,7 @@ impl PinPolicy { /// addition to the [`PinPolicy`]. /// /// This policy must be set when keys are generated or imported, and cannot be changed later. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum TouchPolicy { /// Use the default touch policy for the slot. Default, diff --git a/src/transaction.rs b/src/transaction.rs index 5d961ac..7134676 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -69,7 +69,7 @@ impl<'tx> Transaction<'tx> { pub fn select_application(&self) -> Result<()> { let response = Apdu::new(Ins::SelectApplication) .p1(0x04) - .data(&PIV_AID) + .data(PIV_AID) .transmit(self, 0xFF) .map_err(|e| { error!("failed communicating with card: '{}'", e); @@ -109,7 +109,7 @@ impl<'tx> Transaction<'tx> { // YK4 requires switching to the yk applet to retrieve the serial let sw = Apdu::new(Ins::SelectApplication) .p1(0x04) - .data(&YK_AID) + .data(YK_AID) .transmit(self, 0xFF)? .status_words(); @@ -131,7 +131,7 @@ impl<'tx> Transaction<'tx> { // reselect the PIV applet let sw = Apdu::new(Ins::SelectApplication) .p1(0x04) - .data(&PIV_AID) + .data(PIV_AID) .transmit(self, 0xFF)? .status_words(); @@ -246,7 +246,7 @@ impl<'tx> Transaction<'tx> { let status_words = Apdu::new(Ins::SetMgmKey) .params(0xff, p2) - .data(&data) + .data(data) .transmit(self, 261)? .status_words(); diff --git a/src/yubikey.rs b/src/yubikey.rs index e043390..8ae98a6 100644 --- a/src/yubikey.rs +++ b/src/yubikey.rs @@ -285,7 +285,7 @@ impl YubiKey { // get a challenge from the card let challenge = Apdu::new(Ins::Authenticate) .params(ALGO_3DES, KEY_CARDMGM) - .data(&[TAG_DYN_AUTH, 0x02, 0x80, 0x00]) + .data([TAG_DYN_AUTH, 0x02, 0x80, 0x00]) .transmit(&txn, 261)?; if !challenge.is_success() || challenge.data().len() < 12 { @@ -310,7 +310,7 @@ impl YubiKey { let authentication = Apdu::new(Ins::Authenticate) .params(ALGO_3DES, KEY_CARDMGM) - .data(&data) + .data(data) .transmit(&txn, 261)?; if !authentication.is_success() { @@ -568,7 +568,7 @@ impl YubiKey { let response = Apdu::new(Ins::Authenticate) .params(ALGO_3DES, KEY_CARDMGM) - .data(&[0x7c, 0x02, 0x81, 0x00]) + .data([0x7c, 0x02, 0x81, 0x00]) .transmit(&txn, 261)?; if !response.is_success() { @@ -594,7 +594,7 @@ impl YubiKey { // send the response to the card and a challenge of our own. let status_words = Apdu::new(Ins::Authenticate) .params(ALGO_3DES, KEY_CARDMGM) - .data(&data) + .data(data) .transmit(&txn, 261)? .status_words();