1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-FileCopyrightText: Heiko Schaefer <heiko@schaefer.name>
// SPDX-License-Identifier: MIT OR Apache-2.0

//! # rpgpie 🦀️🔐🥧
//!
//! rpgpie is an experimental higher level [OpenPGP](https://www.rfc-editor.org/rfc/rfc4880)
//! library based on [rPGP](https://github.com/rpgp/rpgp).
//! It exposes a convenient API for some OpenPGP operations, and applies some amount of policy
//! (to limit reliance on obsolete algorithms).
//!
//! The main goals of rpgpie include simplicity, collaboration and fun 🥳.
//!
//! ## "OpenPGP for application developers"
//!
//! rpgpie applies the terminology outlined in the
//! ["OpenPGP for application developers"](https://openpgp.dev/) documentation.
//! We explore designing an API that build on its terminology and concepts.
//!
//! ## Stateless OpenPGP (SOP)
//!
//! See [rsop](https://crates.io/crates/rsop) for a
//! [stateless OpenPGP (SOP)](https://datatracker.ietf.org/doc/draft-dkg-openpgp-stateless-cli/)
//! implementation based on rpgpie.

pub mod card;
pub mod key;
pub mod msg;
pub mod policy;
pub mod sig;
pub(crate) mod util;

/// rpgpie version, via Cargo.toml
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// version of the rpgp dependency we built against
pub const RPGP_VERSION: &str = pgp::VERSION;

/// Enum wrapper for the error types of this crate
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
    #[error("rPGP error: {0}")]
    Rpgp(pgp::errors::Error),

    #[error("OpenPGP card error: {0}")]
    Ocard(openpgp_card::Error),

    #[error("IO error: {0}")]
    Io(std::io::Error),

    #[error("Internal error: {0}")]
    Message(String),

    #[error("No binding signature for the primary key")]
    NoPrimaryBinding,
}

impl From<pgp::errors::Error> for Error {
    fn from(value: pgp::errors::Error) -> Self {
        Error::Rpgp(value)
    }
}

impl From<openpgp_card::Error> for Error {
    fn from(value: openpgp_card::Error) -> Self {
        Error::Ocard(value)
    }
}

impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Error::Io(value)
    }
}

impl From<pgp::SubkeyParamsBuilderError> for Error {
    fn from(value: pgp::SubkeyParamsBuilderError) -> Self {
        Error::Rpgp(pgp::errors::Error::Message(format!(
            "SubkeyParamsBuilderError: {}",
            value
        )))
    }
}

impl From<pgp::SecretKeyParamsBuilderError> for Error {
    fn from(value: pgp::SecretKeyParamsBuilderError) -> Self {
        Error::Rpgp(pgp::errors::Error::Message(format!(
            "SecretKeyParamsBuilderError: {}",
            value
        )))
    }
}