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