Fix clippy lints
This commit is contained in:
parent
b16d657070
commit
0b4a18b136
16 changed files with 63 additions and 66 deletions
|
@ -293,7 +293,7 @@ impl<'a> Open<'a> {
|
|||
// ----------
|
||||
|
||||
pub fn public_key(&mut self, key_type: KeyType) -> Result<PublicKeyMaterial, Error> {
|
||||
self.opt.public_key(key_type).map_err(|e| e.into())
|
||||
self.opt.public_key(key_type)
|
||||
}
|
||||
|
||||
// ----------
|
||||
|
|
|
@ -54,9 +54,9 @@ impl<'a, 'app> CardDecryptor<'a, 'app> {
|
|||
)))
|
||||
}
|
||||
} else {
|
||||
Err(Error::InternalError(format!(
|
||||
"Failed to get the decryption key's Fingerprint from the card"
|
||||
)))
|
||||
Err(Error::InternalError(
|
||||
"Failed to get the decryption key's Fingerprint from the card".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ impl<'a, 'app> CardSigner<'a, 'app> {
|
|||
)))
|
||||
}
|
||||
} else {
|
||||
Err(Error::InternalError(format!(
|
||||
"Failed to get the signing key's Fingerprint from the card"
|
||||
)))
|
||||
Err(Error::InternalError(
|
||||
"Failed to get the signing key's Fingerprint from the card".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ use sequoia_openpgp::policy::Policy;
|
|||
/// `prompt` notifies the user when a pinpad needs the user pin as input.
|
||||
///
|
||||
/// FIXME: accept optional metadata for user_id(s)?
|
||||
pub fn make_cert<'a, 'app>(
|
||||
open: &'a mut Open<'app>,
|
||||
pub fn make_cert<'app>(
|
||||
open: &mut Open<'app>,
|
||||
key_sig: PublicKey,
|
||||
key_dec: Option<PublicKey>,
|
||||
key_aut: Option<PublicKey>,
|
||||
|
|
|
@ -188,9 +188,10 @@ impl Algo {
|
|||
match self {
|
||||
Algo::Rsa(rsa) => Self::rsa_algo_attrs(rsa),
|
||||
Algo::Ecc(ecc) => Self::ecc_algo_attrs(ecc.oid(), ecc.ecc_type()),
|
||||
_ => Err(Error::UnsupportedAlgo(
|
||||
format!("Unexpected Algo {:?}", self).into(),
|
||||
)),
|
||||
_ => Err(Error::UnsupportedAlgo(format!(
|
||||
"Unexpected Algo {:?}",
|
||||
self
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,8 @@ impl TryFrom<Vec<u8>> for RawResponse {
|
|||
type Error = Error;
|
||||
|
||||
fn try_from(mut data: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let sw2 = data
|
||||
.pop()
|
||||
.ok_or_else(|| Error::ResponseLength(data.len()))?;
|
||||
let sw1 = data
|
||||
.pop()
|
||||
.ok_or_else(|| Error::ResponseLength(data.len()))?;
|
||||
let sw2 = data.pop().ok_or(Error::ResponseLength(data.len()))?;
|
||||
let sw1 = data.pop().ok_or(Error::ResponseLength(data.len()))?;
|
||||
|
||||
let status = (sw1, sw2).into();
|
||||
|
||||
|
@ -124,21 +120,21 @@ mod tests {
|
|||
#[test]
|
||||
fn test_two_bytes_data_response() {
|
||||
let res = RawResponse::try_from(vec![0x01, 0x02, 0x90, 0x00]).unwrap();
|
||||
assert_eq!(res.is_ok(), true);
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(res.data, vec![0x01, 0x02]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_data_response() {
|
||||
let res = RawResponse::try_from(vec![0x90, 0x00]).unwrap();
|
||||
assert_eq!(res.is_ok(), true);
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(res.data, vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_more_data_response() {
|
||||
let res = RawResponse::try_from(vec![0xAB, 0x61, 0x02]).unwrap();
|
||||
assert_eq!(res.is_ok(), false);
|
||||
assert!(!res.is_ok());
|
||||
assert_eq!(res.data, vec![0xAB]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,9 +168,9 @@ impl ApplicationRelatedData {
|
|||
|
||||
Ok(kg)
|
||||
} else {
|
||||
Err(Error::NotFound(format!(
|
||||
"Failed to get key generation times."
|
||||
)))
|
||||
Err(Error::NotFound(
|
||||
"Failed to get key generation times.".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ impl Fingerprint {
|
|||
|
||||
/// Helper fn for nom parsing
|
||||
pub(crate) fn complete<O>(result: nom::IResult<&[u8], O>) -> Result<O, Error> {
|
||||
let (rem, output) = result.map_err(|_err| Error::ParseError(format!("Parsing failed")))?;
|
||||
let (rem, output) = result.map_err(|_err| Error::ParseError("Parsing failed".to_string()))?;
|
||||
if rem.is_empty() {
|
||||
Ok(output)
|
||||
} else {
|
||||
|
|
|
@ -79,17 +79,19 @@ impl TryFrom<(&[u8], u16)> for ExtendedCapabilities {
|
|||
let i9 = input[9];
|
||||
|
||||
if i8 > 1 {
|
||||
return Err(Error::ParseError(
|
||||
format!("Illegal value '{}' for pin_block_2_format_support", i8).into(),
|
||||
));
|
||||
return Err(Error::ParseError(format!(
|
||||
"Illegal value '{}' for pin_block_2_format_support",
|
||||
i8
|
||||
)));
|
||||
}
|
||||
|
||||
pin_block_2_format_support = Some(i8 != 0);
|
||||
|
||||
if i9 > 1 {
|
||||
return Err(Error::ParseError(
|
||||
format!("Illegal value '{}' for mse_command_support", i9).into(),
|
||||
));
|
||||
return Err(Error::ParseError(format!(
|
||||
"Illegal value '{}' for mse_command_support",
|
||||
i9
|
||||
)));
|
||||
}
|
||||
mse_command_support = Some(i9 != 0);
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@ impl TryFrom<&[u8]> for Fingerprint {
|
|||
let array: [u8; 20] = input.try_into().unwrap();
|
||||
Ok(array.into())
|
||||
} else {
|
||||
Err(Error::ParseError(
|
||||
format!("Unexpected fingerprint length {}", input.len()).into(),
|
||||
))
|
||||
Err(Error::ParseError(format!(
|
||||
"Unexpected fingerprint length {}",
|
||||
input.len()
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ impl TryFrom<&[u8]> for HistoricalBytes {
|
|||
}
|
||||
|
||||
// workaround-hack for "ledger": fix status indicator byte 7
|
||||
if data == &[0x0, 0x31, 0xc5, 0x73, 0xc0, 0x1, 0x80, 0x7, 0x90, 0x0] {
|
||||
if data == [0x0, 0x31, 0xc5, 0x73, 0xc0, 0x1, 0x80, 0x7, 0x90, 0x0] {
|
||||
data = &[0x0, 0x31, 0xc5, 0x73, 0xc0, 0x1, 0x80, 0x5, 0x90, 0x0];
|
||||
}
|
||||
|
||||
|
@ -94,9 +94,10 @@ impl TryFrom<&[u8]> for HistoricalBytes {
|
|||
if len < 4 {
|
||||
// historical bytes cannot be this short
|
||||
|
||||
return Err(Error::ParseError(
|
||||
format!("Historical bytes too short ({} bytes), must be >= 4", len).into(),
|
||||
));
|
||||
return Err(Error::ParseError(format!(
|
||||
"Historical bytes too short ({} bytes), must be >= 4",
|
||||
len
|
||||
)));
|
||||
}
|
||||
|
||||
if data[0] != 0 {
|
||||
|
@ -126,15 +127,12 @@ impl TryFrom<&[u8]> for HistoricalBytes {
|
|||
// (1 byte for the tl, plus `l` bytes of data for this ctlv)
|
||||
// (e.g. len = 4 -> tl + 3byte data)
|
||||
if ctlv.len() < (1 + l as usize) {
|
||||
return Err(Error::ParseError(
|
||||
format!(
|
||||
return Err(Error::ParseError(format!(
|
||||
"Illegal length value in Historical Bytes TL {} len {} l {}",
|
||||
ctlv[0],
|
||||
ctlv.len(),
|
||||
l
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
)));
|
||||
}
|
||||
|
||||
match (t, l) {
|
||||
|
|
|
@ -67,7 +67,7 @@ impl TryFrom<&[u8]> for KeySet<KeyGenerationTime> {
|
|||
// hasn't been completely consumed.
|
||||
self::key_generation_set(input)
|
||||
.map(|res| res.1)
|
||||
.map_err(|_err| Error::ParseError(format!("Parsing failed")))
|
||||
.map_err(|_err| Error::ParseError("Parsing failed".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -316,8 +316,7 @@ fn card_algo_rsa(algo_info: AlgoInfo, key_type: KeyType, rsa_bits: u16) -> Resul
|
|||
// Get RSA algo attributes
|
||||
let rsa_algos: Vec<_> = keytype_algos
|
||||
.iter()
|
||||
.map(|a| if let Algo::Rsa(r) = a { Some(r) } else { None })
|
||||
.flatten()
|
||||
.filter_map(|a| if let Algo::Rsa(r) = a { Some(r) } else { None })
|
||||
.collect();
|
||||
|
||||
// Filter card algorithms by rsa bitlength of the key we want to upload
|
||||
|
@ -334,9 +333,10 @@ fn card_algo_rsa(algo_info: AlgoInfo, key_type: KeyType, rsa_bits: u16) -> Resul
|
|||
Ok((**algo.last().unwrap()).clone())
|
||||
} else {
|
||||
// RSA with this bit length is not in algo_info
|
||||
return Err(Error::UnsupportedAlgo(
|
||||
format!("RSA {} unsupported according to algo_info", rsa_bits).into(),
|
||||
));
|
||||
return Err(Error::UnsupportedAlgo(format!(
|
||||
"RSA {} unsupported according to algo_info",
|
||||
rsa_bits
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,8 +350,7 @@ fn check_card_algo_ecc(algo_info: AlgoInfo, key_type: KeyType, oid: &[u8]) -> Ve
|
|||
// Get attributes
|
||||
let ecc_algos: Vec<_> = keytype_algos
|
||||
.iter()
|
||||
.map(|a| if let Algo::Ecc(e) = a { Some(e) } else { None })
|
||||
.flatten()
|
||||
.filter_map(|a| if let Algo::Ecc(e) = a { Some(e) } else { None })
|
||||
.collect();
|
||||
|
||||
// Find entries with this OID in the algorithm information for key_type
|
||||
|
|
|
@ -574,8 +574,7 @@ impl<'a> OpenPgpTransaction<'a> {
|
|||
pub fn set_lang(&mut self, lang: &[Lang]) -> Result<(), Error> {
|
||||
let bytes: Vec<u8> = lang
|
||||
.iter()
|
||||
.map(|&l| Into::<Vec<u8>>::into(l))
|
||||
.flatten()
|
||||
.flat_map(|&l| Into::<Vec<u8>>::into(l))
|
||||
.collect();
|
||||
|
||||
let put_lang = commands::put_lang(bytes);
|
||||
|
|
|
@ -71,7 +71,7 @@ fn multi_byte_tag_rest(input: &[u8]) -> nom::IResult<&[u8], &[u8]> {
|
|||
combinator::recognize(sequence::tuple((
|
||||
combinator::verify(number::u8, |c| is_first(c) && !is_last(c)),
|
||||
bytes::take_while(|c| !is_last(&c)),
|
||||
combinator::verify(number::u8, |c| is_last(c)),
|
||||
combinator::verify(number::u8, is_last),
|
||||
)))(input)
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'b> PcscTransaction<'b> {
|
|||
let mut was_reset = false;
|
||||
|
||||
let card_caps = card.card_caps();
|
||||
let reader_caps = card.reader_caps().clone();
|
||||
let reader_caps = card.reader_caps();
|
||||
let mode = card.mode();
|
||||
|
||||
let mut c = card.card();
|
||||
|
@ -100,7 +100,7 @@ impl<'b> PcscTransaction<'b> {
|
|||
let txc = Self {
|
||||
tx,
|
||||
card_caps,
|
||||
reader_caps: reader_caps.clone(),
|
||||
reader_caps,
|
||||
};
|
||||
|
||||
break Ok(txc);
|
||||
|
@ -131,9 +131,10 @@ impl<'b> PcscTransaction<'b> {
|
|||
}
|
||||
Err((_, e)) => {
|
||||
log::debug!("start_tx: error {:?}", e);
|
||||
break Err(
|
||||
Error::Smartcard(SmartcardError::Error(format!("Error: {:?}", e))).into(),
|
||||
);
|
||||
break Err(Error::Smartcard(SmartcardError::Error(format!(
|
||||
"Error: {:?}",
|
||||
e
|
||||
))));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -510,7 +511,7 @@ impl PcscBackend {
|
|||
fn cards_filter(ident: Option<&str>, mode: pcsc::ShareMode) -> Result<Vec<Self>, Error> {
|
||||
let mut cards: Vec<Self> = vec![];
|
||||
|
||||
for mut card in Self::raw_pcsc_cards(mode).map_err(|sce| Error::Smartcard(sce))? {
|
||||
for mut card in Self::raw_pcsc_cards(mode).map_err(Error::Smartcard)? {
|
||||
log::debug!("cards_filter: next card");
|
||||
log::debug!(" status: {:x?}", card.status2_owned());
|
||||
|
||||
|
|
|
@ -326,7 +326,7 @@ fn decrypt(
|
|||
let p = StandardPolicy::new();
|
||||
let cert = Cert::from_file(cert_file)?;
|
||||
|
||||
let input = util::open_or_stdin(input.as_deref())?;
|
||||
let input = util::open_or_stdin(input)?;
|
||||
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut pgp = OpenPgp::new(&mut card);
|
||||
|
@ -352,7 +352,7 @@ fn sign_detached(
|
|||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cert = Cert::from_file(cert_file)?;
|
||||
|
||||
let mut input = util::open_or_stdin(input.as_deref())?;
|
||||
let mut input = util::open_or_stdin(input)?;
|
||||
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut pgp = OpenPgp::new(&mut card);
|
||||
|
|
Loading…
Reference in a new issue