Move KeySet from card_do.rs to lib.rs

(It is not a DO, only a container to conveniently handle triples of DO)
This commit is contained in:
Heiko Schaefer 2021-09-02 21:59:05 +02:00
parent 6b3ae2cf62
commit f5b31aac26
3 changed files with 36 additions and 36 deletions

View file

@ -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;

View file

@ -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<T> {
signature: Option<T>,
decryption: Option<T>,
authentication: Option<T>,
}
impl<T> From<(Option<T>, Option<T>, Option<T>)> for KeySet<T> {
fn from(tuple: (Option<T>, Option<T>, Option<T>)) -> Self {
Self {
signature: tuple.0,
decryption: tuple.1,
authentication: tuple.2,
}
}
}
impl<T> KeySet<T> {
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<O>(
result: nom::IResult<&[u8], O>,
) -> Result<O, anyhow::Error> {

View file

@ -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<T> {
signature: Option<T>,
decryption: Option<T>,
authentication: Option<T>,
}
impl<T> From<(Option<T>, Option<T>, Option<T>)> for KeySet<T> {
fn from(tuple: (Option<T>, Option<T>, Option<T>)) -> Self {
Self {
signature: tuple.0,
decryption: tuple.1,
authentication: tuple.2,
}
}
}
impl<T> KeySet<T> {
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()
}
}