From 27697cb2c5a057232c26bc84f11ea20cfbac9fc6 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Thu, 3 Nov 2022 11:44:59 +0100 Subject: [PATCH] add rustfmt.toml and set group_imports = "StdExternalCrate" --- .gitlab-ci.yml | 4 ++-- card-functionality/src/cards.rs | 6 +++--- card-functionality/src/import.rs | 5 ++--- card-functionality/src/keygen.rs | 2 +- card-functionality/src/list-cards.rs | 1 - card-functionality/src/other.rs | 1 - card-functionality/src/tests.rs | 15 +++++++-------- card-functionality/src/util.rs | 11 +++++------ openpgp-card-examples/src/bin/decrypt.rs | 5 ++--- openpgp-card-examples/src/bin/detach-sign.rs | 3 +-- openpgp-card-sequoia/examples/test.rs | 10 ++++------ openpgp-card-sequoia/src/decryptor.rs | 4 +--- openpgp-card-sequoia/src/lib.rs | 13 +++++++------ openpgp-card-sequoia/src/privkey.rs | 3 +-- openpgp-card-sequoia/src/signer.rs | 4 +--- openpgp-card-sequoia/src/sq_util.rs | 4 ++-- openpgp-card-sequoia/src/util.rs | 4 +--- openpgp-card/src/algorithm.rs | 6 +++--- openpgp-card/src/apdu/response.rs | 6 ++++-- openpgp-card/src/card_do.rs | 3 ++- openpgp-card/src/card_do/algo_info.rs | 2 +- openpgp-card/src/card_do/application_id.rs | 3 ++- openpgp-card/src/card_do/extended_cap.rs | 6 ++++-- openpgp-card/src/card_do/extended_length_info.rs | 3 ++- openpgp-card/src/card_do/fingerprint.rs | 3 ++- openpgp-card/src/card_do/historical.rs | 6 ++++-- openpgp-card/src/card_do/key_generation_times.rs | 11 +++++++---- openpgp-card/src/card_do/pw_status.rs | 6 ++++-- openpgp-card/src/lib.rs | 5 ++--- openpgp-card/src/tlv.rs | 6 ++++-- pcsc/src/lib.rs | 2 +- rustfmt.toml | 4 ++++ scdc/src/lib.rs | 6 +++--- tools/src/bin/opgpcard/commands/admin.rs | 13 +++++-------- tools/src/bin/opgpcard/commands/attestation.rs | 3 +-- tools/src/bin/opgpcard/commands/decrypt.rs | 5 ++--- tools/src/bin/opgpcard/commands/pin.rs | 1 - tools/src/bin/opgpcard/commands/pubkey.rs | 10 ++++------ tools/src/bin/opgpcard/commands/sign.rs | 5 ++--- tools/src/bin/opgpcard/commands/ssh.rs | 3 +-- tools/src/bin/opgpcard/commands/status.rs | 3 +-- tools/src/bin/opgpcard/main.rs | 4 +--- tools/src/bin/opgpcard/util.rs | 2 +- tools/src/bin/opgpcard/versioned_output.rs | 3 ++- 44 files changed, 109 insertions(+), 116 deletions(-) create mode 100644 rustfmt.toml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8380575..076a034 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,10 +39,10 @@ cargo-fmt: stage: lint image: rust:latest before_script: - - rustup component add rustfmt + - rustup toolchain install nightly && rustup component add --toolchain nightly rustfmt - *report-rust script: - - cargo fmt -- --check + - cargo +nightly fmt -- --check cache: [ ] cargo-deny: diff --git a/card-functionality/src/cards.rs b/card-functionality/src/cards.rs index 2a8a5c1..ea551df 100644 --- a/card-functionality/src/cards.rs +++ b/card-functionality/src/cards.rs @@ -4,14 +4,14 @@ //! Wrapping of cards for tests. Open a list of cards, based on a //! TestConfig configuration file -use anyhow::Result; -use pcsc::ShareMode; -use serde_derive::Deserialize; use std::collections::BTreeMap; +use anyhow::Result; use openpgp_card::{CardBackend, Error}; use openpgp_card_pcsc::PcscBackend; use openpgp_card_scdc::ScdBackend; +use pcsc::ShareMode; +use serde_derive::Deserialize; const SHARE_MODE: Option = Some(ShareMode::Shared); diff --git a/card-functionality/src/import.rs b/card-functionality/src/import.rs index 8b96415..42bb2d4 100644 --- a/card-functionality/src/import.rs +++ b/card-functionality/src/import.rs @@ -1,14 +1,13 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; use std::str::FromStr; -use sequoia_openpgp::Cert; - +use anyhow::Result; use card_functionality::cards::TestConfig; use card_functionality::tests::*; use card_functionality::util; +use sequoia_openpgp::Cert; fn main() -> Result<()> { env_logger::init(); diff --git a/card-functionality/src/keygen.rs b/card-functionality/src/keygen.rs index d906d20..a561488 100644 --- a/card-functionality/src/keygen.rs +++ b/card-functionality/src/keygen.rs @@ -1,9 +1,9 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; use std::str::FromStr; +use anyhow::Result; use card_functionality::cards::TestConfig; use card_functionality::tests::*; use card_functionality::util; diff --git a/card-functionality/src/list-cards.rs b/card-functionality/src/list-cards.rs index 627a95d..c96a72a 100644 --- a/card-functionality/src/list-cards.rs +++ b/card-functionality/src/list-cards.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use anyhow::Result; - use openpgp_card_pcsc::PcscBackend; use openpgp_card_sequoia::{state::Open, Card}; diff --git a/card-functionality/src/other.rs b/card-functionality/src/other.rs index 8e0815c..b061b93 100644 --- a/card-functionality/src/other.rs +++ b/card-functionality/src/other.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use anyhow::Result; - use card_functionality::cards::TestConfig; use card_functionality::tests::*; diff --git a/card-functionality/src/tests.rs b/card-functionality/src/tests.rs index b445007..236c9a1 100644 --- a/card-functionality/src/tests.rs +++ b/card-functionality/src/tests.rs @@ -1,18 +1,11 @@ // SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; use std::convert::TryFrom; use std::str::FromStr; use std::string::FromUtf8Error; -use thiserror; - -use sequoia_openpgp::parse::Parse; -use sequoia_openpgp::policy::StandardPolicy; -use sequoia_openpgp::serialize::SerializeInto; -use sequoia_openpgp::types::{HashAlgorithm, SymmetricAlgorithm}; -use sequoia_openpgp::Cert; +use anyhow::Result; use openpgp_card::algorithm::AlgoSimple; use openpgp_card::card_do::{KeyGenerationTime, Sex}; use openpgp_card::{Error, KeyType, OpenPgp, OpenPgpTransaction, StatusBytes}; @@ -21,6 +14,12 @@ use openpgp_card_sequoia::util::{ make_cert, public_key_material_and_fp_to_key, public_key_material_to_key, }; use openpgp_card_sequoia::{state::Transaction, Card}; +use sequoia_openpgp::parse::Parse; +use sequoia_openpgp::policy::StandardPolicy; +use sequoia_openpgp::serialize::SerializeInto; +use sequoia_openpgp::types::{HashAlgorithm, SymmetricAlgorithm}; +use sequoia_openpgp::Cert; +use thiserror; use crate::cards::TestCardData; use crate::util; diff --git a/card-functionality/src/util.rs b/card-functionality/src/util.rs index b55509c..c25a4a6 100644 --- a/card-functionality/src/util.rs +++ b/card-functionality/src/util.rs @@ -1,10 +1,14 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; use std::io::Write; use std::time::SystemTime; +use anyhow::Result; +use openpgp_card::card_do::KeyGenerationTime; +use openpgp_card::{KeyType, OpenPgpTransaction}; +use openpgp_card_sequoia::sq_util; +use openpgp_card_sequoia::util::vka_as_uploadable_key; use sequoia_openpgp::parse::stream::{ DetachedVerifierBuilder, MessageLayer, MessageStructure, VerificationHelper, }; @@ -13,11 +17,6 @@ use sequoia_openpgp::policy::{Policy, StandardPolicy}; use sequoia_openpgp::serialize::stream::{Armorer, Encryptor, LiteralWriter, Message}; use sequoia_openpgp::Cert; -use openpgp_card::card_do::KeyGenerationTime; -use openpgp_card::{KeyType, OpenPgpTransaction}; -use openpgp_card_sequoia::sq_util; -use openpgp_card_sequoia::util::vka_as_uploadable_key; - pub const SP: &StandardPolicy = &StandardPolicy::new(); pub(crate) fn upload_subkeys( diff --git a/openpgp-card-examples/src/bin/decrypt.rs b/openpgp-card-examples/src/bin/decrypt.rs index ee90d7c..c66d177 100644 --- a/openpgp-card-examples/src/bin/decrypt.rs +++ b/openpgp-card-examples/src/bin/decrypt.rs @@ -1,11 +1,10 @@ // SPDX-FileCopyrightText: 2021 Wiktor Kwapisiewicz // SPDX-License-Identifier: MIT OR Apache-2.0 -use openpgp_card_pcsc::PcscBackend; -use openpgp_card_sequoia::{state::Open, Card}; - use openpgp::parse::{stream::DecryptorBuilder, Parse}; use openpgp::policy::StandardPolicy; +use openpgp_card_pcsc::PcscBackend; +use openpgp_card_sequoia::{state::Open, Card}; use sequoia_openpgp as openpgp; fn main() -> Result<(), Box> { diff --git a/openpgp-card-examples/src/bin/detach-sign.rs b/openpgp-card-examples/src/bin/detach-sign.rs index fa72315..2684109 100644 --- a/openpgp-card-examples/src/bin/detach-sign.rs +++ b/openpgp-card-examples/src/bin/detach-sign.rs @@ -1,10 +1,9 @@ // SPDX-FileCopyrightText: 2021 Wiktor Kwapisiewicz // SPDX-License-Identifier: MIT OR Apache-2.0 +use openpgp::serialize::stream::{Armorer, Message, Signer}; use openpgp_card_pcsc::PcscBackend; use openpgp_card_sequoia::{state::Open, Card}; - -use openpgp::serialize::stream::{Armorer, Message, Signer}; use sequoia_openpgp as openpgp; fn main() -> Result<(), Box> { diff --git a/openpgp-card-sequoia/examples/test.rs b/openpgp-card-sequoia/examples/test.rs index 42e834c..d6bf652 100644 --- a/openpgp-card-sequoia/examples/test.rs +++ b/openpgp-card-sequoia/examples/test.rs @@ -1,20 +1,18 @@ // SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; use std::env; use std::error::Error; -use sequoia_openpgp::parse::Parse; -use sequoia_openpgp::policy::StandardPolicy; -use sequoia_openpgp::Cert; - +use anyhow::Result; use openpgp_card::card_do::Sex; use openpgp_card::KeyType; use openpgp_card_pcsc::PcscBackend; - use openpgp_card_sequoia::sq_util; use openpgp_card_sequoia::{state::Open, Card}; +use sequoia_openpgp::parse::Parse; +use sequoia_openpgp::policy::StandardPolicy; +use sequoia_openpgp::Cert; // Filename of test key and test message to use diff --git a/openpgp-card-sequoia/src/decryptor.rs b/openpgp-card-sequoia/src/decryptor.rs index 387e15c..f86bfcf 100644 --- a/openpgp-card-sequoia/src/decryptor.rs +++ b/openpgp-card-sequoia/src/decryptor.rs @@ -2,17 +2,15 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use anyhow::anyhow; - use openpgp::crypto; use openpgp::crypto::mpi; use openpgp::crypto::SessionKey; use openpgp::packet; use openpgp::parse::stream::{DecryptionHelper, MessageStructure, VerificationHelper}; use openpgp::types::{Curve, SymmetricAlgorithm}; -use sequoia_openpgp as openpgp; - use openpgp_card::crypto_data::Cryptogram; use openpgp_card::OpenPgpTransaction; +use sequoia_openpgp as openpgp; use crate::PublicKey; diff --git a/openpgp-card-sequoia/src/lib.rs b/openpgp-card-sequoia/src/lib.rs index b17fa72..b4006df 100644 --- a/openpgp-card-sequoia/src/lib.rs +++ b/openpgp-card-sequoia/src/lib.rs @@ -141,12 +141,6 @@ //! # } //! ``` -use crate::decryptor::CardDecryptor; -use crate::signer::CardSigner; -use crate::state::{Admin, Open, Sign, State, Transaction, User}; -use crate::util::{ - public_key_material_and_fp_to_key, public_to_fingerprint, vka_as_uploadable_key, -}; use openpgp::packet::{key, Key}; use openpgp_card::algorithm::{Algo, AlgoInfo, AlgoSimple}; use openpgp_card::card_do::{ @@ -161,6 +155,13 @@ use sequoia_openpgp::cert::prelude::ValidErasedKeyAmalgamation; use sequoia_openpgp::packet::key::SecretParts; use sequoia_openpgp::types::{HashAlgorithm, SymmetricAlgorithm}; +use crate::decryptor::CardDecryptor; +use crate::signer::CardSigner; +use crate::state::{Admin, Open, Sign, State, Transaction, User}; +use crate::util::{ + public_key_material_and_fp_to_key, public_to_fingerprint, vka_as_uploadable_key, +}; + mod decryptor; mod privkey; mod signer; diff --git a/openpgp-card-sequoia/src/privkey.rs b/openpgp-card-sequoia/src/privkey.rs index d5dbb0b..4967bb2 100644 --- a/openpgp-card-sequoia/src/privkey.rs +++ b/openpgp-card-sequoia/src/privkey.rs @@ -12,11 +12,10 @@ use openpgp::packet::{ Key, }; use openpgp::types::Timestamp; -use sequoia_openpgp as openpgp; - use openpgp_card::card_do::{Fingerprint, KeyGenerationTime}; use openpgp_card::crypto_data::{CardUploadableKey, EccKey, EccType, PrivateKeyMaterial, RSAKey}; use openpgp_card::Error; +use sequoia_openpgp as openpgp; use sequoia_openpgp::types::Curve; /// A SequoiaKey represents the private cryptographic key material of an diff --git a/openpgp-card-sequoia/src/signer.rs b/openpgp-card-sequoia/src/signer.rs index ca56835..fd2294d 100644 --- a/openpgp-card-sequoia/src/signer.rs +++ b/openpgp-card-sequoia/src/signer.rs @@ -4,14 +4,12 @@ use std::convert::TryInto; use anyhow::anyhow; - use openpgp::crypto; use openpgp::crypto::mpi; use openpgp::types::{Curve, PublicKeyAlgorithm}; -use sequoia_openpgp as openpgp; - use openpgp_card::crypto_data::Hash; use openpgp_card::OpenPgpTransaction; +use sequoia_openpgp as openpgp; use crate::PublicKey; diff --git a/openpgp-card-sequoia/src/sq_util.rs b/openpgp-card-sequoia/src/sq_util.rs index e141f41..1b16fd6 100644 --- a/openpgp-card-sequoia/src/sq_util.rs +++ b/openpgp-card-sequoia/src/sq_util.rs @@ -5,9 +5,9 @@ //! //! These helpers are (almost) entirely unrelated to OpenPGP card. -use anyhow::{anyhow, Context, Result}; use std::io; +use anyhow::{anyhow, Context, Result}; use openpgp::armor; use openpgp::cert::amalgamation::key::{ErasedKeyAmalgamation, ValidErasedKeyAmalgamation}; use openpgp::crypto; @@ -19,10 +19,10 @@ use openpgp::parse::{ use openpgp::policy::Policy; use openpgp::serialize::stream::{Message, Signer}; use openpgp::{Cert, Fingerprint}; +use openpgp_card::{Error, KeyType}; use sequoia_openpgp as openpgp; use crate::{CardDecryptor, CardSigner}; -use openpgp_card::{Error, KeyType}; /// Retrieve a (sub)key from a Cert, for a given KeyType. /// diff --git a/openpgp-card-sequoia/src/util.rs b/openpgp-card-sequoia/src/util.rs index 34d4530..c3a8302 100644 --- a/openpgp-card-sequoia/src/util.rs +++ b/openpgp-card-sequoia/src/util.rs @@ -7,7 +7,6 @@ use std::convert::TryFrom; use std::convert::TryInto; use anyhow::{anyhow, Result}; - use openpgp::cert::amalgamation::key::ValidErasedKeyAmalgamation; use openpgp::crypto::mpi; use openpgp::packet::Signature; @@ -20,12 +19,11 @@ use openpgp::types::{ HashAlgorithm, KeyFlags, PublicKeyAlgorithm, SignatureType, SymmetricAlgorithm, Timestamp, }; use openpgp::{Cert, Packet}; -use sequoia_openpgp as openpgp; - use openpgp_card::algorithm::{Algo, Curve}; use openpgp_card::card_do::{Fingerprint, KeyGenerationTime}; use openpgp_card::crypto_data::{CardUploadableKey, PublicKeyMaterial}; use openpgp_card::{Error, KeyType}; +use sequoia_openpgp as openpgp; use crate::privkey::SequoiaKey; use crate::state::Transaction; diff --git a/openpgp-card/src/algorithm.rs b/openpgp-card/src/algorithm.rs index e37a515..c063b47 100644 --- a/openpgp-card/src/algorithm.rs +++ b/openpgp-card/src/algorithm.rs @@ -9,13 +9,13 @@ //! [`AlgoSimple`] offers a shorthand for specifying an algorithm, //! specifically for key generation on the card. +use std::convert::TryFrom; +use std::fmt; + use crate::card_do::ApplicationRelatedData; use crate::crypto_data::EccType; use crate::{keys, oid, Error, KeyType}; -use std::convert::TryFrom; -use std::fmt; - /// A shorthand way to specify algorithms (e.g. for key generation). #[derive(Clone, Copy, Debug)] #[non_exhaustive] diff --git a/openpgp-card/src/apdu/response.rs b/openpgp-card/src/apdu/response.rs index cbdad72..3b01d42 100644 --- a/openpgp-card/src/apdu/response.rs +++ b/openpgp-card/src/apdu/response.rs @@ -1,9 +1,10 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{Error, StatusBytes}; use std::convert::{TryFrom, TryInto}; +use crate::{Error, StatusBytes}; + /// Response from the card to a command. /// /// This object contains pure payload, without the status bytes. @@ -114,9 +115,10 @@ impl TryFrom> for RawResponse { #[cfg(test)] mod tests { - use crate::apdu::response::RawResponse; use std::convert::TryFrom; + use crate::apdu::response::RawResponse; + #[test] fn test_two_bytes_data_response() { let res = RawResponse::try_from(vec![0x01, 0x02, 0x90, 0x00]).unwrap(); diff --git a/openpgp-card/src/card_do.rs b/openpgp-card/src/card_do.rs index 9fc1ce4..1ea5560 100644 --- a/openpgp-card/src/card_do.rs +++ b/openpgp-card/src/card_do.rs @@ -3,11 +3,12 @@ //! OpenPGP card data objects (DO) -use chrono::{DateTime, Utc}; use std::convert::{TryFrom, TryInto}; use std::fmt::{Display, Formatter, Write}; use std::time::{Duration, UNIX_EPOCH}; +use chrono::{DateTime, Utc}; + use crate::{algorithm::Algo, tlv::Tlv, Error, KeySet, KeyType, Tags}; mod algo_attrs; diff --git a/openpgp-card/src/card_do/algo_info.rs b/openpgp-card/src/card_do/algo_info.rs index 5d5539b..37bbfd1 100644 --- a/openpgp-card/src/card_do/algo_info.rs +++ b/openpgp-card/src/card_do/algo_info.rs @@ -4,11 +4,11 @@ //! 4.4.3.11 Algorithm Information use std::convert::TryFrom; +use std::fmt; use nom::branch::alt; use nom::combinator::map; use nom::{branch, bytes::complete as bytes, combinator, multi, sequence}; -use std::fmt; use crate::algorithm::{Algo, AlgoInfo}; use crate::card_do::{algo_attrs, complete}; diff --git a/openpgp-card/src/card_do/application_id.rs b/openpgp-card/src/card_do/application_id.rs index 6bf7a90..579d8f6 100644 --- a/openpgp-card/src/card_do/application_id.rs +++ b/openpgp-card/src/card_do/application_id.rs @@ -3,9 +3,10 @@ //! 4.2.1 Application Identifier (AID) -use nom::{bytes::complete as bytes, number::complete as number}; use std::convert::TryFrom; +use nom::{bytes::complete as bytes, number::complete as number}; + use crate::card_do::{complete, ApplicationIdentifier}; fn parse(input: &[u8]) -> nom::IResult<&[u8], ApplicationIdentifier> { diff --git a/openpgp-card/src/card_do/extended_cap.rs b/openpgp-card/src/card_do/extended_cap.rs index f6d3b5e..542d2c9 100644 --- a/openpgp-card/src/card_do/extended_cap.rs +++ b/openpgp-card/src/card_do/extended_cap.rs @@ -122,10 +122,12 @@ impl TryFrom<(&[u8], u16)> for ExtendedCapabilities { #[cfg(test)] mod test { - use crate::card_do::extended_cap::ExtendedCapabilities; - use hex_literal::hex; use std::convert::TryFrom; + use hex_literal::hex; + + use crate::card_do::extended_cap::ExtendedCapabilities; + #[test] fn test_yk5() { // YubiKey 5 diff --git a/openpgp-card/src/card_do/extended_length_info.rs b/openpgp-card/src/card_do/extended_length_info.rs index 2e4f550..6513309 100644 --- a/openpgp-card/src/card_do/extended_length_info.rs +++ b/openpgp-card/src/card_do/extended_length_info.rs @@ -4,10 +4,11 @@ //! 4.1.3.1 Extended length information //! (Introduced in V3.0) +use std::convert::TryFrom; + use nom::{bytes::complete::tag, number::complete as number, sequence}; use crate::card_do::{complete, ExtendedLengthInfo}; -use std::convert::TryFrom; fn parse(input: &[u8]) -> nom::IResult<&[u8], (u16, u16)> { let (input, (_, cmd, _, resp)) = nom::combinator::all_consuming(sequence::tuple(( diff --git a/openpgp-card/src/card_do/fingerprint.rs b/openpgp-card/src/card_do/fingerprint.rs index 9b50a8d..6c0ea9a 100644 --- a/openpgp-card/src/card_do/fingerprint.rs +++ b/openpgp-card/src/card_do/fingerprint.rs @@ -3,11 +3,12 @@ //! Fingerprint for a single key slot -use nom::{bytes::complete as bytes, combinator, sequence}; use std::convert::TryFrom; use std::convert::TryInto; use std::fmt; +use nom::{bytes::complete as bytes, combinator, sequence}; + use crate::card_do::{Fingerprint, KeySet}; use crate::Error; diff --git a/openpgp-card/src/card_do/historical.rs b/openpgp-card/src/card_do/historical.rs index 8e3574d..971bb40 100644 --- a/openpgp-card/src/card_do/historical.rs +++ b/openpgp-card/src/card_do/historical.rs @@ -3,9 +3,10 @@ //! 6 Historical Bytes +use std::convert::TryFrom; + use crate::card_do::{CardCapabilities, CardServiceData, HistoricalBytes}; use crate::Error; -use std::convert::TryFrom; impl CardCapabilities { pub fn command_chaining(&self) -> bool { @@ -199,9 +200,10 @@ impl TryFrom<&[u8]> for HistoricalBytes { #[cfg(test)] mod test { - use super::*; use std::convert::TryInto; + use super::*; + #[test] fn test_split_tl() { assert_eq!(split_tl(0x31), (3, 1)); diff --git a/openpgp-card/src/card_do/key_generation_times.rs b/openpgp-card/src/card_do/key_generation_times.rs index 75c8421..1638083 100644 --- a/openpgp-card/src/card_do/key_generation_times.rs +++ b/openpgp-card/src/card_do/key_generation_times.rs @@ -3,11 +3,13 @@ //! Generation date/time of key pair (see spec pg. 24) -use crate::card_do::{KeyGenerationTime, KeySet}; -use crate::Error; +use std::convert::TryFrom; + use chrono::{DateTime, NaiveDateTime, Utc}; use nom::{combinator, number::complete as number, sequence}; -use std::convert::TryFrom; + +use crate::card_do::{KeyGenerationTime, KeySet}; +use crate::Error; impl From for DateTime { fn from(kg: KeyGenerationTime) -> Self { @@ -73,9 +75,10 @@ impl TryFrom<&[u8]> for KeySet { #[cfg(test)] mod test { - use super::*; use std::convert::TryInto; + use super::*; + #[test] fn test() { let data3 = [ diff --git a/openpgp-card/src/card_do/pw_status.rs b/openpgp-card/src/card_do/pw_status.rs index ae16b5d..5fd9e1c 100644 --- a/openpgp-card/src/card_do/pw_status.rs +++ b/openpgp-card/src/card_do/pw_status.rs @@ -3,9 +3,10 @@ //! PW status Bytes (see spec page 23) +use std::convert::TryFrom; + use crate::card_do::PWStatusBytes; use crate::Error; -use std::convert::TryFrom; impl PWStatusBytes { /// PUT DO for PW Status Bytes accepts either 1 or 4 bytes of data. @@ -75,9 +76,10 @@ impl TryFrom<&[u8]> for PWStatusBytes { #[cfg(test)] mod test { - use super::*; use std::convert::TryInto; + use super::*; + #[test] fn test() { let data = [0x0, 0x40, 0x40, 0x40, 0x3, 0x0, 0x3]; diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index ca27022..4119254 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -38,14 +38,13 @@ mod oid; mod openpgp; mod tlv; -pub use crate::errors::{Error, SmartcardError, StatusBytes}; -pub use crate::openpgp::{OpenPgp, OpenPgpTransaction}; - use std::convert::TryInto; use std::ops::{Deref, DerefMut}; use crate::apdu::commands; use crate::card_do::ApplicationRelatedData; +pub use crate::errors::{Error, SmartcardError, StatusBytes}; +pub use crate::openpgp::{OpenPgp, OpenPgpTransaction}; use crate::tlv::{tag::Tag, value::Value, Tlv}; /// The CardBackend trait defines a connection with an OpenPGP card via a diff --git a/openpgp-card/src/tlv.rs b/openpgp-card/src/tlv.rs index 2151d48..b661f93 100644 --- a/openpgp-card/src/tlv.rs +++ b/openpgp-card/src/tlv.rs @@ -5,9 +5,10 @@ pub(crate) mod length; pub(crate) mod tag; pub(crate) mod value; -use nom::{bytes::complete as bytes, combinator}; use std::convert::TryFrom; +use nom::{bytes::complete as bytes, combinator}; + use crate::card_do::complete; use crate::tlv::{length::tlv_encode_length, tag::Tag, value::Value}; @@ -81,9 +82,10 @@ impl TryFrom<&[u8]> for Tlv { #[cfg(test)] mod test { - use hex_literal::hex; use std::convert::TryFrom; + use hex_literal::hex; + use super::{Tlv, Value}; use crate::{Error, Tags}; diff --git a/pcsc/src/lib.rs b/pcsc/src/lib.rs index 0c2364b..c7b93f1 100644 --- a/pcsc/src/lib.rs +++ b/pcsc/src/lib.rs @@ -5,10 +5,10 @@ //! `openpgp-card`. It uses the PCSC middleware to access the OpenPGP //! application on smart cards. -use iso7816_tlv::simple::Tlv; use std::collections::HashMap; use std::convert::TryInto; +use iso7816_tlv::simple::Tlv; use openpgp_card::card_do::ApplicationRelatedData; use openpgp_card::{CardBackend, CardCaps, CardTransaction, Error, PinType, SmartcardError}; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..2e1ff90 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2022 Heiko Schaefer +# SPDX-License-Identifier: CC0-1.0 + +group_imports = "StdExternalCrate" diff --git a/scdc/src/lib.rs b/scdc/src/lib.rs index bcdaacf..2dc8fb5 100644 --- a/scdc/src/lib.rs +++ b/scdc/src/lib.rs @@ -7,15 +7,15 @@ //! //! Note that (unlike `openpgp-card-pcsc`), this backend doesn't implement transaction guarantees. +use std::sync::Mutex; + use futures::StreamExt; use lazy_static::lazy_static; +use openpgp_card::{CardBackend, CardCaps, CardTransaction, Error, PinType, SmartcardError}; use sequoia_ipc::assuan::Response; use sequoia_ipc::gnupg::{Agent, Context}; -use std::sync::Mutex; use tokio::runtime::Runtime; -use openpgp_card::{CardBackend, CardCaps, CardTransaction, Error, PinType, SmartcardError}; - lazy_static! { static ref RT: Mutex = Mutex::new(tokio::runtime::Runtime::new().unwrap()); } diff --git a/tools/src/bin/opgpcard/commands/admin.rs b/tools/src/bin/opgpcard/commands/admin.rs index a6f19b0..130b08a 100644 --- a/tools/src/bin/opgpcard/commands/admin.rs +++ b/tools/src/bin/opgpcard/commands/admin.rs @@ -3,16 +3,15 @@ // SPDX-FileCopyrightText: 2022 Nora Widdecke // SPDX-License-Identifier: MIT OR Apache-2.0 +use std::path::PathBuf; + use anyhow::{anyhow, Result}; use clap::{Parser, ValueEnum}; use openpgp_card_sequoia::state::{Admin, Open, Transaction}; +use openpgp_card_sequoia::types::AlgoSimple; use openpgp_card_sequoia::util::public_key_material_to_key; -use sequoia_openpgp::types::{HashAlgorithm, SymmetricAlgorithm}; - -use std::path::PathBuf; - use openpgp_card_sequoia::{sq_util, PublicKey}; - +use openpgp_card_sequoia::{types::KeyType, Card}; use sequoia_openpgp::cert::prelude::ValidErasedKeyAmalgamation; use sequoia_openpgp::packet::key::{SecretParts, UnspecifiedRole}; use sequoia_openpgp::packet::Key; @@ -20,11 +19,9 @@ use sequoia_openpgp::parse::Parse; use sequoia_openpgp::policy::Policy; use sequoia_openpgp::policy::StandardPolicy; use sequoia_openpgp::serialize::SerializeInto; +use sequoia_openpgp::types::{HashAlgorithm, SymmetricAlgorithm}; use sequoia_openpgp::Cert; -use openpgp_card_sequoia::types::AlgoSimple; -use openpgp_card_sequoia::{types::KeyType, Card}; - use crate::versioned_output::{OutputBuilder, OutputFormat, OutputVersion}; use crate::{output, util, ENTER_ADMIN_PIN, ENTER_USER_PIN}; diff --git a/tools/src/bin/opgpcard/commands/attestation.rs b/tools/src/bin/opgpcard/commands/attestation.rs index 357a044..9d003b1 100644 --- a/tools/src/bin/opgpcard/commands/attestation.rs +++ b/tools/src/bin/opgpcard/commands/attestation.rs @@ -7,9 +7,8 @@ use std::path::PathBuf; use anyhow::Result; use clap::{Parser, ValueEnum}; -use openpgp_card_sequoia::{state::Open, Card}; - use openpgp_card_sequoia::types::KeyType; +use openpgp_card_sequoia::{state::Open, Card}; use crate::versioned_output::{OutputBuilder, OutputFormat, OutputVersion}; use crate::ENTER_USER_PIN; diff --git a/tools/src/bin/opgpcard/commands/decrypt.rs b/tools/src/bin/opgpcard/commands/decrypt.rs index 9fe6bc6..d153cc4 100644 --- a/tools/src/bin/opgpcard/commands/decrypt.rs +++ b/tools/src/bin/opgpcard/commands/decrypt.rs @@ -2,11 +2,10 @@ // SPDX-FileCopyrightText: 2022 Nora Widdecke // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{anyhow, Result}; -use clap::Parser; - use std::path::PathBuf; +use anyhow::{anyhow, Result}; +use clap::Parser; use openpgp_card_sequoia::{state::Open, Card}; use sequoia_openpgp::{ parse::{stream::DecryptorBuilder, Parse}, diff --git a/tools/src/bin/opgpcard/commands/pin.rs b/tools/src/bin/opgpcard/commands/pin.rs index 4e12f2f..73b42e4 100644 --- a/tools/src/bin/opgpcard/commands/pin.rs +++ b/tools/src/bin/opgpcard/commands/pin.rs @@ -6,7 +6,6 @@ use std::path::PathBuf; use anyhow::Result; use clap::Parser; - use openpgp_card_sequoia::{state::Open, state::Transaction, Card}; use crate::util; diff --git a/tools/src/bin/opgpcard/commands/pubkey.rs b/tools/src/bin/opgpcard/commands/pubkey.rs index ba09100..19b2e7a 100644 --- a/tools/src/bin/opgpcard/commands/pubkey.rs +++ b/tools/src/bin/opgpcard/commands/pubkey.rs @@ -3,16 +3,14 @@ // SPDX-FileCopyrightText: 2022 Nora Widdecke // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::Result; -use clap::Parser; - use std::path::PathBuf; -use openpgp_card_sequoia::{state::Open, Card}; -use sequoia_openpgp::serialize::SerializeInto; - +use anyhow::Result; +use clap::Parser; use openpgp_card_sequoia::types::KeyType; use openpgp_card_sequoia::util::public_key_material_and_fp_to_key; +use openpgp_card_sequoia::{state::Open, Card}; +use sequoia_openpgp::serialize::SerializeInto; use crate::output; use crate::pick_card_for_reading; diff --git a/tools/src/bin/opgpcard/commands/sign.rs b/tools/src/bin/opgpcard/commands/sign.rs index 469e4d3..6632ab8 100644 --- a/tools/src/bin/opgpcard/commands/sign.rs +++ b/tools/src/bin/opgpcard/commands/sign.rs @@ -2,11 +2,10 @@ // SPDX-FileCopyrightText: 2022 Nora Widdecke // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{anyhow, Result}; -use clap::Parser; - use std::path::{Path, PathBuf}; +use anyhow::{anyhow, Result}; +use clap::Parser; use openpgp_card_sequoia::{state::Open, Card}; use sequoia_openpgp::serialize::stream::{Armorer, Message, Signer}; diff --git a/tools/src/bin/opgpcard/commands/ssh.rs b/tools/src/bin/opgpcard/commands/ssh.rs index fa97f12..7999579 100644 --- a/tools/src/bin/opgpcard/commands/ssh.rs +++ b/tools/src/bin/opgpcard/commands/ssh.rs @@ -5,9 +5,8 @@ use anyhow::Result; use clap::Parser; -use openpgp_card_sequoia::{state::Open, Card}; - use openpgp_card_sequoia::types::KeyType; +use openpgp_card_sequoia::{state::Open, Card}; use crate::output; use crate::pick_card_for_reading; diff --git a/tools/src/bin/opgpcard/commands/status.rs b/tools/src/bin/opgpcard/commands/status.rs index 2229395..06084b9 100644 --- a/tools/src/bin/opgpcard/commands/status.rs +++ b/tools/src/bin/opgpcard/commands/status.rs @@ -5,9 +5,8 @@ use anyhow::Result; use clap::Parser; -use openpgp_card_sequoia::{state::Open, Card}; - use openpgp_card_sequoia::types::KeyType; +use openpgp_card_sequoia::{state::Open, Card}; use crate::output; use crate::pick_card_for_reading; diff --git a/tools/src/bin/opgpcard/main.rs b/tools/src/bin/opgpcard/main.rs index 219b9cc..00f19b7 100644 --- a/tools/src/bin/opgpcard/main.rs +++ b/tools/src/bin/opgpcard/main.rs @@ -5,13 +5,11 @@ use anyhow::Result; use clap::Parser; - -use sequoia_openpgp::Cert; - use openpgp_card_sequoia::types::CardBackend; use openpgp_card_sequoia::util::make_cert; use openpgp_card_sequoia::PublicKey; use openpgp_card_sequoia::{state::Open, state::Transaction, Card}; +use sequoia_openpgp::Cert; mod cli; mod commands; diff --git a/tools/src/bin/opgpcard/util.rs b/tools/src/bin/opgpcard/util.rs index 4ce0cce..6e3e08d 100644 --- a/tools/src/bin/opgpcard/util.rs +++ b/tools/src/bin/opgpcard/util.rs @@ -1,9 +1,9 @@ // SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{anyhow, Context, Result}; use std::path::{Path, PathBuf}; +use anyhow::{anyhow, Context, Result}; use openpgp_card_pcsc::PcscBackend; use openpgp_card_sequoia::state::{Admin, Sign, Transaction, User}; use openpgp_card_sequoia::types::{ diff --git a/tools/src/bin/opgpcard/versioned_output.rs b/tools/src/bin/opgpcard/versioned_output.rs index c8078b6..b0c3804 100644 --- a/tools/src/bin/opgpcard/versioned_output.rs +++ b/tools/src/bin/opgpcard/versioned_output.rs @@ -1,10 +1,11 @@ // SPDX-FileCopyrightText: 2022 Lars Wirzenius // SPDX-License-Identifier: MIT OR Apache-2.0 +use std::str::FromStr; + use clap::ValueEnum; use semver::Version; use serde::{Serialize, Serializer}; -use std::str::FromStr; #[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)] pub enum OutputFormat {