Skip to main content

openpgp_card/
errors.rs

1// SPDX-FileCopyrightText: Heiko Schaefer <heiko@schaefer.name>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Error types used by this crate.
5//!
6//! [`Error`] is a wrapper enum for all error types that are used.
7//!
8//! The two main classes of errors are:
9//! - [`SmartcardError`], for problems on the reader/smartcard layer
10//! - [`StatusBytes`], which models error statuses reported by the OpenPGP card application
11
12use card_backend::SmartcardError;
13
14use crate::ocard::StatusBytes;
15
16/// Enum wrapper for the error types of this crate
17#[derive(thiserror::Error, Debug)]
18#[non_exhaustive]
19pub enum Error {
20    #[error("Error interacting with smartcard: {0}")]
21    Smartcard(#[from] SmartcardError),
22
23    #[error("OpenPGP card error status: {0}")]
24    CardStatus(#[from] StatusBytes),
25
26    #[error("Command too long ({0} bytes)")]
27    CommandTooLong(usize),
28
29    #[error("Unexpected response length: {0}")]
30    ResponseLength(usize),
31
32    #[error("Data not found: {0}")]
33    NotFound(String),
34
35    #[error("Couldn't parse data: {0}")]
36    ParseError(String),
37
38    #[error("Unsupported algorithm: {0}")]
39    UnsupportedAlgo(String),
40
41    #[error("Unsupported feature: {0}")]
42    UnsupportedFeature(String),
43
44    // FIXME: placeholder, remove again later?
45    #[error("Internal error: {0}")]
46    InternalError(String),
47}