From 56d03ffca6d9e5aba1510a49e5296b0269055770 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Thu, 24 Feb 2022 21:15:43 +0100 Subject: [PATCH] Drop use of "anyhow". --- openpgp-card/Cargo.toml | 1 - openpgp-card/src/algorithm.rs | 7 +++---- openpgp-card/src/apdu.rs | 1 - openpgp-card/src/apdu/command.rs | 2 -- openpgp-card/src/card_do/algo_attrs.rs | 1 - openpgp-card/src/card_do/algo_info.rs | 1 - openpgp-card/src/card_do/application_id.rs | 1 - openpgp-card/src/card_do/cardholder.rs | 2 -- openpgp-card/src/card_do/extended_length_info.rs | 1 - openpgp-card/src/card_do/historical.rs | 13 ++++++------- openpgp-card/src/crypto_data.rs | 2 -- openpgp-card/src/lib.rs | 1 - openpgp-card/src/tlv.rs | 7 +++---- openpgp-card/src/tlv/value.rs | 2 -- pcsc/Cargo.toml | 1 - scdc/Cargo.toml | 1 - 16 files changed, 12 insertions(+), 32 deletions(-) diff --git a/openpgp-card/Cargo.toml b/openpgp-card/Cargo.toml index cb9d82b..ca6e1d3 100644 --- a/openpgp-card/Cargo.toml +++ b/openpgp-card/Cargo.toml @@ -16,7 +16,6 @@ blanket = "0.2.0" nom = "6" hex-literal = "0.3" hex-slice = "0.1" -anyhow = "1" thiserror = "1" env_logger = "0.8" log = "0.4" diff --git a/openpgp-card/src/algorithm.rs b/openpgp-card/src/algorithm.rs index 93fc260..8bb0057 100644 --- a/openpgp-card/src/algorithm.rs +++ b/openpgp-card/src/algorithm.rs @@ -13,7 +13,6 @@ use crate::card_do::ApplicationRelatedData; use crate::crypto_data::EccType; use crate::{keys, Error, KeyType}; -use anyhow::{anyhow, Result}; use std::convert::TryFrom; use std::fmt; @@ -32,9 +31,9 @@ pub enum AlgoSimple { } impl TryFrom<&str> for AlgoSimple { - type Error = anyhow::Error; + type Error = crate::Error; - fn try_from(algo: &str) -> Result { + fn try_from(algo: &str) -> Result { use AlgoSimple::*; Ok(match algo { @@ -46,7 +45,7 @@ impl TryFrom<&str> for AlgoSimple { "NIST384" => NIST384, "NIST521" => NIST521, "Curve25519" => Curve25519, - _ => return Err(anyhow!("unexpected algo {}", algo)), + _ => return Err(Error::UnsupportedAlgo(format!("unexpected algo {}", algo))), }) } } diff --git a/openpgp-card/src/apdu.rs b/openpgp-card/src/apdu.rs index 1d8c3f6..88c2c90 100644 --- a/openpgp-card/src/apdu.rs +++ b/openpgp-card/src/apdu.rs @@ -8,7 +8,6 @@ pub(crate) mod command; pub(crate) mod commands; pub mod response; -use anyhow::Result; use std::convert::TryFrom; use crate::apdu::command::Expect; diff --git a/openpgp-card/src/apdu/command.rs b/openpgp-card/src/apdu/command.rs index 81dc83c..2e37bfe 100644 --- a/openpgp-card/src/apdu/command.rs +++ b/openpgp-card/src/apdu/command.rs @@ -4,8 +4,6 @@ //! Data structure for APDU Commands //! (Commands get sent to the card, which will usually send back a `Response`) -use anyhow::Result; - #[derive(Clone, Copy)] pub enum Expect { Empty, diff --git a/openpgp-card/src/card_do/algo_attrs.rs b/openpgp-card/src/card_do/algo_attrs.rs index d793743..f4e1f99 100644 --- a/openpgp-card/src/card_do/algo_attrs.rs +++ b/openpgp-card/src/card_do/algo_attrs.rs @@ -5,7 +5,6 @@ use std::convert::TryFrom; -use anyhow::Result; use nom::branch::alt; use nom::bytes::complete::tag; use nom::combinator::map; diff --git a/openpgp-card/src/card_do/algo_info.rs b/openpgp-card/src/card_do/algo_info.rs index 816687d..0f0a2c0 100644 --- a/openpgp-card/src/card_do/algo_info.rs +++ b/openpgp-card/src/card_do/algo_info.rs @@ -5,7 +5,6 @@ use std::convert::TryFrom; -use anyhow::Result; use nom::branch::alt; use nom::combinator::map; use nom::{branch, bytes::complete as bytes, combinator, multi, sequence}; diff --git a/openpgp-card/src/card_do/application_id.rs b/openpgp-card/src/card_do/application_id.rs index cab10f1..a5e6cd0 100644 --- a/openpgp-card/src/card_do/application_id.rs +++ b/openpgp-card/src/card_do/application_id.rs @@ -3,7 +3,6 @@ //! 4.2.1 Application Identifier (AID) -use anyhow::Result; use nom::{bytes::complete as bytes, number::complete as number}; use std::convert::TryFrom; diff --git a/openpgp-card/src/card_do/cardholder.rs b/openpgp-card/src/card_do/cardholder.rs index 221e0db..9f7704d 100644 --- a/openpgp-card/src/card_do/cardholder.rs +++ b/openpgp-card/src/card_do/cardholder.rs @@ -5,8 +5,6 @@ use std::convert::TryFrom; -use anyhow::Result; - use crate::card_do::{CardholderRelatedData, Lang, Sex}; use crate::tlv::{value::Value, Tlv}; diff --git a/openpgp-card/src/card_do/extended_length_info.rs b/openpgp-card/src/card_do/extended_length_info.rs index de7f443..2e4f550 100644 --- a/openpgp-card/src/card_do/extended_length_info.rs +++ b/openpgp-card/src/card_do/extended_length_info.rs @@ -4,7 +4,6 @@ //! 4.1.3.1 Extended length information //! (Introduced in V3.0) -use anyhow::Result; use nom::{bytes::complete::tag, number::complete as number, sequence}; use crate::card_do::{complete, ExtendedLengthInfo}; diff --git a/openpgp-card/src/card_do/historical.rs b/openpgp-card/src/card_do/historical.rs index 969ea42..f590cdb 100644 --- a/openpgp-card/src/card_do/historical.rs +++ b/openpgp-card/src/card_do/historical.rs @@ -198,7 +198,6 @@ impl TryFrom<&[u8]> for HistoricalBytes { #[cfg(test)] mod test { use super::*; - use anyhow::Result; use std::convert::TryInto; #[test] @@ -210,7 +209,7 @@ mod test { } #[test] - fn test_gnuk() -> Result<()> { + fn test_gnuk() -> Result<(), Error> { // gnuk 1.2 stable let data: &[u8] = &[0x0, 0x31, 0x84, 0x73, 0x80, 0x1, 0x80, 0x5, 0x90, 0x0]; let hist: HistoricalBytes = data.try_into()?; @@ -240,7 +239,7 @@ mod test { } #[test] - fn test_floss34() -> Result<()> { + fn test_floss34() -> Result<(), Error> { // floss shop openpgp smartcard 3.4 let data: &[u8] = &[0x0, 0x31, 0xf5, 0x73, 0xc0, 0x1, 0x60, 0x5, 0x90, 0x0]; let hist: HistoricalBytes = data.try_into()?; @@ -270,7 +269,7 @@ mod test { } #[test] - fn test_yk5() -> Result<()> { + fn test_yk5() -> Result<(), Error> { // yubikey 5 let data: &[u8] = &[0x0, 0x73, 0x0, 0x0, 0xe0, 0x5, 0x90, 0x0]; let hist: HistoricalBytes = data.try_into()?; @@ -293,7 +292,7 @@ mod test { } #[test] - fn test_yk4() -> Result<()> { + fn test_yk4() -> Result<(), Error> { // yubikey 4 let data: &[u8] = &[0x0, 0x73, 0x0, 0x0, 0x80, 0x5, 0x90, 0x0]; let hist: HistoricalBytes = data.try_into()?; @@ -316,7 +315,7 @@ mod test { } #[test] - fn test_yk_neo() -> Result<()> { + fn test_yk_neo() -> Result<(), Error> { // yubikey neo let data: &[u8] = &[ 0x0, 0x73, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -341,7 +340,7 @@ mod test { } #[test] - fn test_ledger_nano_s() -> Result<()> { + fn test_ledger_nano_s() -> Result<(), Error> { let data: &[u8] = &[ 0x0, 0x31, 0xc5, 0x73, 0xc0, 0x1, 0x80, 0x7, 0x90, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ]; diff --git a/openpgp-card/src/crypto_data.rs b/openpgp-card/src/crypto_data.rs index 587cf0b..0ecb984 100644 --- a/openpgp-card/src/crypto_data.rs +++ b/openpgp-card/src/crypto_data.rs @@ -5,8 +5,6 @@ //! Private key data, public key data, cryptograms for decryption, hash //! data for signing. -use anyhow::Result; - use crate::algorithm::Algo; use crate::card_do::{Fingerprint, KeyGenerationTime}; use crate::Error; diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index 27ed054..e784705 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -37,7 +37,6 @@ mod tlv; pub use crate::errors::{Error, SmartcardError, StatusBytes}; pub use crate::openpgp::{OpenPgp, OpenPgpTransaction}; -use anyhow::Result; use std::convert::TryInto; use std::ops::{Deref, DerefMut}; diff --git a/openpgp-card/src/tlv.rs b/openpgp-card/src/tlv.rs index 3df3915..61e86ce 100644 --- a/openpgp-card/src/tlv.rs +++ b/openpgp-card/src/tlv.rs @@ -5,7 +5,6 @@ pub(crate) mod length; pub(crate) mod tag; pub(crate) mod value; -use anyhow::Result; use nom::{bytes::complete as bytes, combinator}; use std::convert::TryFrom; @@ -81,11 +80,11 @@ impl TryFrom<&[u8]> for Tlv { #[cfg(test)] mod test { - use anyhow::Result; use hex_literal::hex; use std::convert::TryFrom; use super::{Tlv, Value}; + use crate::Error; #[test] fn test_tlv0() { @@ -102,7 +101,7 @@ mod test { ); } #[test] - fn test_tlv() -> Result<()> { + fn test_tlv() -> Result<(), Error> { // From OpenPGP card spec ยง 7.2.6 let data = hex!("5B0B546573743C3C54657374695F2D0264655F350131").to_vec(); @@ -127,7 +126,7 @@ mod test { } #[test] - fn test_tlv_yubi5() -> Result<()> { + fn test_tlv_yubi5() -> Result<(), Error> { // 'Yubikey 5 NFC' output for GET DATA on "Application Related Data" let data = hex!("6e8201374f10d27600012401030400061601918000005f520800730000e00590007f740381012073820110c00a7d000bfe080000ff0000c106010800001100c206010800001100c306010800001100da06010800001100c407ff7f7f7f030003c5500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cd1000000000000000000000000000000000de0801000200030081027f660802020bfe02020bfed6020020d7020020d8020020d9020020"); let tlv = Tlv::try_from(&data[..])?; diff --git a/openpgp-card/src/tlv/value.rs b/openpgp-card/src/tlv/value.rs index fe49c5f..8322848 100644 --- a/openpgp-card/src/tlv/value.rs +++ b/openpgp-card/src/tlv/value.rs @@ -3,8 +3,6 @@ //! Value in a TLV data structure -use anyhow::Result; - use crate::card_do::complete; use crate::tlv::Tlv; diff --git a/pcsc/Cargo.toml b/pcsc/Cargo.toml index 4581d70..9388a0b 100644 --- a/pcsc/Cargo.toml +++ b/pcsc/Cargo.toml @@ -15,5 +15,4 @@ documentation = "https://docs.rs/crate/openpgp-card-pcsc" openpgp-card = { path = "../openpgp-card", version = "0.1" } iso7816-tlv = "0.4" pcsc = "2.7" -anyhow = "1" log = "0.4" diff --git a/scdc/Cargo.toml b/scdc/Cargo.toml index 16eca9e..46bd644 100644 --- a/scdc/Cargo.toml +++ b/scdc/Cargo.toml @@ -15,7 +15,6 @@ documentation = "https://docs.rs/crate/openpgp-card-scdc" openpgp-card = { path = "../openpgp-card", version = "0.1" } sequoia-ipc = "0.26" hex = "0.4" -anyhow = "1" futures = "0.3" tokio = "0.2" lazy_static = "1.4"