Add #[non_exhaustive] to error and crypto_data enums.

This commit is contained in:
Heiko Schaefer 2021-09-01 22:46:04 +02:00
parent 84a7f0060d
commit f501c09d2f
3 changed files with 11 additions and 0 deletions

View file

@ -172,6 +172,7 @@ pub fn public_key_material_to_key(
panic!("unexpected algo {:?}", algo);
}
}
_ => unimplemented!("Unexpected PublicKeyMaterial type"),
}
}

View file

@ -12,6 +12,7 @@ use crate::card_do::{Fingerprint, KeyGenerationTime};
use crate::errors::OpenpgpCardError;
/// A hash value that can be signed by the card.
#[non_exhaustive]
pub enum Hash<'a> {
SHA256([u8; 0x20]),
SHA384([u8; 0x30]),
@ -49,6 +50,7 @@ impl Hash<'_> {
}
/// Data that can be decrypted on the card.
#[non_exhaustive]
pub enum Cryptogram<'a> {
// message/ciphertext
RSA(&'a [u8]),
@ -74,6 +76,7 @@ pub trait CardUploadableKey {
/// Algorithm-independent container for private key material to upload to
/// an OpenPGP card
#[non_exhaustive]
pub enum PrivateKeyMaterial {
R(Box<dyn RSAKey>),
E(Box<dyn EccKey>),
@ -99,6 +102,7 @@ pub trait EccKey {
/// Algorithm-independent container for public key material retrieved from
/// an OpenPGP card
#[derive(Debug)]
#[non_exhaustive]
pub enum PublicKeyMaterial {
R(RSAPub),
E(EccPub),
@ -106,6 +110,7 @@ pub enum PublicKeyMaterial {
/// RSA-specific container for public key material from an OpenPGP card.
#[derive(Debug)]
#[non_exhaustive]
pub struct RSAPub {
/// Modulus (a number denoted as n coded on x bytes)
n: Vec<u8>,
@ -130,6 +135,7 @@ impl RSAPub {
/// ECC-specific container for public key material from an OpenPGP card.
#[derive(Debug)]
#[non_exhaustive]
pub struct EccPub {
data: Vec<u8>,
algo: Algo,
@ -151,6 +157,7 @@ impl EccPub {
/// A marker to distinguish between elliptic curve algorithms (ECDH, ECDSA,
/// EdDSA)
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
#[non_exhaustive]
pub enum EccType {
ECDH,
ECDSA,

View file

@ -14,6 +14,7 @@ use thiserror::Error;
/// Enum that wraps the different error types that this crate can return
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum OpenpgpCardError {
#[error("Error interacting with smartcard: {0}")]
Smartcard(SmartcardError),
@ -45,6 +46,7 @@ impl From<anyhow::Error> for OpenpgpCardError {
/// OpenPGP card "Status Byte" errors
#[derive(Error, Debug, PartialEq)]
#[non_exhaustive]
pub enum OcErrorStatus {
#[error("Selected file or DO in termination state")]
TerminationState,
@ -150,6 +152,7 @@ impl From<(u8, u8)> for OcErrorStatus {
/// Errors on the smartcard/reader layer
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum SmartcardError {
#[error("Failed to create a pcsc smartcard context {0}")]
ContextError(String),