From f5b31aac2646084919d45e05ca475b0dc23bc9a0 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Thu, 2 Sep 2021 21:59:05 +0200 Subject: [PATCH] Move KeySet from card_do.rs to lib.rs (It is not a DO, only a container to conveniently handle triples of DO) --- openpgp-card-sequoia/src/lib.rs | 4 ++-- openpgp-card/src/card_do.rs | 36 ++------------------------------- openpgp-card/src/lib.rs | 32 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/openpgp-card-sequoia/src/lib.rs b/openpgp-card-sequoia/src/lib.rs index 10d1235..cb3c167 100644 --- a/openpgp-card-sequoia/src/lib.rs +++ b/openpgp-card-sequoia/src/lib.rs @@ -34,14 +34,14 @@ use openpgp_card::algorithm::{Algo, AlgoInfo, Curve}; use openpgp_card::card_do::{ ApplicationIdentifier, ApplicationRelatedData, CardholderRelatedData, ExtendedCapabilities, ExtendedLengthInfo, Features, Fingerprint, - HistoricalBytes, KeyGenerationTime, KeySet, PWStatusBytes, + HistoricalBytes, KeyGenerationTime, PWStatusBytes, SecuritySupportTemplate, Sex, }; use openpgp_card::crypto_data::{ CardUploadableKey, Cryptogram, EccKey, EccType, Hash, PrivateKeyMaterial, PublicKeyMaterial, RSAKey, }; -use openpgp_card::{CardApp, CardClientBox, Error, KeyType, Response}; +use openpgp_card::{CardApp, CardClientBox, Error, KeySet, KeyType, Response}; use crate::signer::CardSigner; diff --git a/openpgp-card/src/card_do.rs b/openpgp-card/src/card_do.rs index dfa506b..13925f6 100644 --- a/openpgp-card/src/card_do.rs +++ b/openpgp-card/src/card_do.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; use std::convert::TryFrom; use std::convert::TryInto; -use crate::{algorithm::Algo, tlv::Tlv, Error, KeyType}; +use crate::{algorithm::Algo, tlv::Tlv, Error, KeySet, KeyType}; mod algo_attrs; mod algo_info; @@ -334,39 +334,7 @@ impl PWStatusBytes { #[derive(Clone, Eq, PartialEq)] pub struct Fingerprint([u8; 20]); -/// A KeySet binds together a triple of information about each Key on a card -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct KeySet { - signature: Option, - decryption: Option, - authentication: Option, -} - -impl From<(Option, Option, Option)> for KeySet { - fn from(tuple: (Option, Option, Option)) -> Self { - Self { - signature: tuple.0, - decryption: tuple.1, - authentication: tuple.2, - } - } -} - -impl KeySet { - pub fn signature(&self) -> Option<&T> { - self.signature.as_ref() - } - - pub fn decryption(&self) -> Option<&T> { - self.decryption.as_ref() - } - - pub fn authentication(&self) -> Option<&T> { - self.authentication.as_ref() - } -} - -/// nom parsing helper +/// Helper fn for nom parsing pub(crate) fn complete( result: nom::IResult<&[u8], O>, ) -> Result { diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index fb68f59..dc7190a 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -160,3 +160,35 @@ impl KeyType { } } } + +/// A KeySet binds together a triple of information about each Key on a card +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct KeySet { + signature: Option, + decryption: Option, + authentication: Option, +} + +impl From<(Option, Option, Option)> for KeySet { + fn from(tuple: (Option, Option, Option)) -> Self { + Self { + signature: tuple.0, + decryption: tuple.1, + authentication: tuple.2, + } + } +} + +impl KeySet { + pub fn signature(&self) -> Option<&T> { + self.signature.as_ref() + } + + pub fn decryption(&self) -> Option<&T> { + self.decryption.as_ref() + } + + pub fn authentication(&self) -> Option<&T> { + self.authentication.as_ref() + } +}