Fix build and clippy warnings (#433)

This commit is contained in:
Tony Arcieri (iqlusion)
2022-11-12 14:15:42 -07:00
committed by GitHub
parent 87ed7b2338
commit 4310cc0f9a
8 changed files with 19 additions and 21 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ jobs:
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: 1.60.0 # MSRV toolchain: 1.65.0
components: clippy components: clippy
override: true override: true
- run: sudo apt-get install libpcsclite-dev - run: sudo apt-get install libpcsclite-dev
+2 -4
View File
@@ -140,14 +140,12 @@ impl Status {
/// Print the given message to stdout /// Print the given message to stdout
pub fn print_stdout(self, msg: impl AsRef<str>) { pub fn print_stdout(self, msg: impl AsRef<str>) {
self.print(&*STDOUT, msg) self.print(&STDOUT, msg).expect("error printing to stdout!")
.expect("error printing to stdout!")
} }
/// Print the given message to stderr /// Print the given message to stderr
pub fn print_stderr(self, msg: impl AsRef<str>) { pub fn print_stderr(self, msg: impl AsRef<str>) {
self.print(&*STDERR, msg) self.print(&STDERR, msg).expect("error printing to stderr!")
.expect("error printing to stderr!")
} }
/// Print the given message /// Print the given message
+1 -1
View File
@@ -97,7 +97,7 @@ impl Serial {
} }
/// Information about how a [`Certificate`] is stored within a YubiKey. /// Information about how a [`Certificate`] is stored within a YubiKey.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CertInfo { pub enum CertInfo {
/// The certificate is uncompressed. /// The certificate is uncompressed.
Uncompressed, Uncompressed,
+1 -1
View File
@@ -404,7 +404,7 @@ fn is_weak_key(key: &[u8; DES_LEN_3DES]) -> bool {
c = (c & 0x0F) + ((c >> 4) & 0x0F); c = (c & 0x0F) + ((c >> 4) & 0x0F);
// if count is even, set low key bit to 1, otherwise 0 // 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 // check odd parity key against table by DES key block
+4 -4
View File
@@ -143,7 +143,7 @@ impl TryFrom<u8> for SlotId {
0xf9 => Ok(SlotId::Attestation), 0xf9 => Ok(SlotId::Attestation),
_ => RetiredSlotId::try_from(value) _ => RetiredSlotId::try_from(value)
.map(SlotId::Retired) .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 _ => s
.parse() .parse()
.map(SlotId::Management) .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. /// Management slot IDs.
#[allow(missing_docs)] #[allow(missing_docs)]
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Ord, PartialOrd)]
pub enum ManagementSlotId { pub enum ManagementSlotId {
PIN, PIN,
PUK, PUK,
@@ -670,7 +670,7 @@ pub fn generate(
} }
} }
let value = &response.data()[..]; let value = response.data();
read_public_key(algorithm, value, true) read_public_key(algorithm, value, true)
} }
+2 -2
View File
@@ -6,7 +6,7 @@ use crate::{serialization::Tlv, Error, Result};
/// given slot. /// given slot.
/// ///
/// This policy must be set when keys are generated or imported, and cannot be changed later. /// 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 { pub enum PinPolicy {
/// Use the default PIN policy for the slot. See the slot's documentation for details. /// Use the default PIN policy for the slot. See the slot's documentation for details.
Default, Default,
@@ -64,7 +64,7 @@ impl PinPolicy {
/// addition to the [`PinPolicy`]. /// addition to the [`PinPolicy`].
/// ///
/// This policy must be set when keys are generated or imported, and cannot be changed later. /// 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 { pub enum TouchPolicy {
/// Use the default touch policy for the slot. /// Use the default touch policy for the slot.
Default, Default,
+4 -4
View File
@@ -69,7 +69,7 @@ impl<'tx> Transaction<'tx> {
pub fn select_application(&self) -> Result<()> { pub fn select_application(&self) -> Result<()> {
let response = Apdu::new(Ins::SelectApplication) let response = Apdu::new(Ins::SelectApplication)
.p1(0x04) .p1(0x04)
.data(&PIV_AID) .data(PIV_AID)
.transmit(self, 0xFF) .transmit(self, 0xFF)
.map_err(|e| { .map_err(|e| {
error!("failed communicating with card: '{}'", 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 // YK4 requires switching to the yk applet to retrieve the serial
let sw = Apdu::new(Ins::SelectApplication) let sw = Apdu::new(Ins::SelectApplication)
.p1(0x04) .p1(0x04)
.data(&YK_AID) .data(YK_AID)
.transmit(self, 0xFF)? .transmit(self, 0xFF)?
.status_words(); .status_words();
@@ -131,7 +131,7 @@ impl<'tx> Transaction<'tx> {
// reselect the PIV applet // reselect the PIV applet
let sw = Apdu::new(Ins::SelectApplication) let sw = Apdu::new(Ins::SelectApplication)
.p1(0x04) .p1(0x04)
.data(&PIV_AID) .data(PIV_AID)
.transmit(self, 0xFF)? .transmit(self, 0xFF)?
.status_words(); .status_words();
@@ -246,7 +246,7 @@ impl<'tx> Transaction<'tx> {
let status_words = Apdu::new(Ins::SetMgmKey) let status_words = Apdu::new(Ins::SetMgmKey)
.params(0xff, p2) .params(0xff, p2)
.data(&data) .data(data)
.transmit(self, 261)? .transmit(self, 261)?
.status_words(); .status_words();
+4 -4
View File
@@ -285,7 +285,7 @@ impl YubiKey {
// get a challenge from the card // get a challenge from the card
let challenge = Apdu::new(Ins::Authenticate) let challenge = Apdu::new(Ins::Authenticate)
.params(ALGO_3DES, KEY_CARDMGM) .params(ALGO_3DES, KEY_CARDMGM)
.data(&[TAG_DYN_AUTH, 0x02, 0x80, 0x00]) .data([TAG_DYN_AUTH, 0x02, 0x80, 0x00])
.transmit(&txn, 261)?; .transmit(&txn, 261)?;
if !challenge.is_success() || challenge.data().len() < 12 { if !challenge.is_success() || challenge.data().len() < 12 {
@@ -310,7 +310,7 @@ impl YubiKey {
let authentication = Apdu::new(Ins::Authenticate) let authentication = Apdu::new(Ins::Authenticate)
.params(ALGO_3DES, KEY_CARDMGM) .params(ALGO_3DES, KEY_CARDMGM)
.data(&data) .data(data)
.transmit(&txn, 261)?; .transmit(&txn, 261)?;
if !authentication.is_success() { if !authentication.is_success() {
@@ -568,7 +568,7 @@ impl YubiKey {
let response = Apdu::new(Ins::Authenticate) let response = Apdu::new(Ins::Authenticate)
.params(ALGO_3DES, KEY_CARDMGM) .params(ALGO_3DES, KEY_CARDMGM)
.data(&[0x7c, 0x02, 0x81, 0x00]) .data([0x7c, 0x02, 0x81, 0x00])
.transmit(&txn, 261)?; .transmit(&txn, 261)?;
if !response.is_success() { if !response.is_success() {
@@ -594,7 +594,7 @@ impl YubiKey {
// send the response to the card and a challenge of our own. // send the response to the card and a challenge of our own.
let status_words = Apdu::new(Ins::Authenticate) let status_words = Apdu::new(Ins::Authenticate)
.params(ALGO_3DES, KEY_CARDMGM) .params(ALGO_3DES, KEY_CARDMGM)
.data(&data) .data(data)
.transmit(&txn, 261)? .transmit(&txn, 261)?
.status_words(); .status_words();