openpgp_card_rpgp/
lib.rs

1// SPDX-FileCopyrightText: Wiktor Kwapisiewicz <wiktor@metacode.biz>
2// SPDX-FileCopyrightText: Heiko Schaefer <heiko@schaefer.name>
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! This is a crate for using
6//! [OpenPGP card devices](https://en.wikipedia.org/wiki/OpenPGP_card) with
7//! the [`rPGP`](https://crates.io/crates/pgp) OpenPGP library.
8//!
9//! In fact, this crate is a supplement for the
10//! [`openpgp-card`](https://crates.io/crates/openpgp-card) crate.
11//! This crate, `openpgp-card-rpgp`, enables performing OpenPGP-specific
12//! operations on cards, by leveraging both the `rPGP` library and `openpgp-card`.
13//! If you want to use this crate, you will probably also want to use
14//! `openpgp-card` itself:
15//!
16//! Much of the functionality of an OpenPGP card device doesn't actually
17//! involve the OpenPGP format. All of that functionality is available in
18//! `openpgp-card`, without requiring support for the OpenPGP format.
19//!
20//! This crate implements additional support for operations that *do* require
21//! handling the OpenPGP format:
22//!
23//! - Creating OpenPGP signatures
24//! - Decryption of OpenPGP data
25//! - Import of OpenPGP private key material
26//!
27//! See this project's "examples" for some pointers on how to use this crate.
28
29mod cardslot;
30mod private;
31mod rpgp;
32
33use std::fmt::Debug;
34
35pub use cardslot::CardSlot;
36pub use private::UploadableKey;
37pub use rpgp::{
38    bind_into_certificate, public_key_material_and_fp_to_key, public_key_material_to_key,
39    public_to_fingerprint,
40};
41
42/// Enum wrapper for the error types of this crate
43#[derive(thiserror::Error, Debug)]
44#[non_exhaustive]
45pub enum Error {
46    #[error("rPGP error: {0}")]
47    Rpgp(pgp::errors::Error),
48
49    #[error("OpenPGP card error: {0}")]
50    Ocard(openpgp_card::Error),
51
52    #[error("Internal error: {0}")]
53    Message(String),
54}
55
56impl From<pgp::errors::Error> for Error {
57    fn from(value: pgp::errors::Error) -> Self {
58        Error::Rpgp(value)
59    }
60}
61
62impl From<openpgp_card::Error> for Error {
63    fn from(value: openpgp_card::Error) -> Self {
64        Error::Ocard(value)
65    }
66}