rpgpie/lib.rs
1// SPDX-FileCopyrightText: Heiko Schaefer <heiko@schaefer.name>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! # rpgpie 🦀️🔐🥧
5//!
6//! rpgpie is an experimental higher level [OpenPGP](https://www.rfc-editor.org/rfc/rfc9850)
7//! library based on [rPGP](https://github.com/rpgp/rpgp).
8//!
9//! It exposes a convenient API for some simple common OpenPGP operations.
10//!
11//! rpgpie implements semantics for OpenPGP expiration and revocation mechanisms, key flags,
12//! and applies some amount of policy (to limit reliance on obsolete algorithms).
13//!
14//! Main goals of rpgpie include simplicity and collaboration 🥳.
15//!
16//! ## "OpenPGP for application developers"
17//!
18//! rpgpie aims to apply the terminology outlined in the
19//! ["OpenPGP for application developers"](https://openpgp.dev/) documentation.
20//!
21//! ## Stateless OpenPGP (SOP)
22//!
23//! See [rsop](https://crates.io/crates/rsop) for a
24//! [stateless OpenPGP (SOP)](https://datatracker.ietf.org/doc/draft-dkg-openpgp-stateless-cli/)
25//! tool based on rpgpie.
26
27pub mod certificate;
28pub mod key;
29pub mod merge;
30pub mod message;
31pub mod model;
32pub mod policy;
33pub mod signature;
34pub mod tsk;
35pub mod util;
36
37/// rpgpie version, via Cargo.toml
38pub const VERSION: &str = env!("CARGO_PKG_VERSION");
39
40/// Version of the rPGP dependency we built against
41pub const RPGP_VERSION: &str = pgp::VERSION;
42
43/// Error type for this crate
44#[derive(thiserror::Error, Debug)]
45#[non_exhaustive]
46pub enum Error {
47 #[error("rPGP error: {0}")]
48 Rpgp(pgp::errors::Error),
49
50 #[error("IO error: {0}")]
51 Io(std::io::Error),
52
53 #[error("Internal error: {0}")]
54 Message(String),
55
56 #[error("Primary key invalid: No valid binding signature found")]
57 InvalidPrimary,
58}
59
60impl From<pgp::errors::Error> for Error {
61 fn from(value: pgp::errors::Error) -> Self {
62 Error::Rpgp(value)
63 }
64}
65
66impl From<std::io::Error> for Error {
67 fn from(value: std::io::Error) -> Self {
68 Error::Io(value)
69 }
70}
71
72impl From<pgp::composed::SubkeyParamsBuilderError> for Error {
73 fn from(value: pgp::composed::SubkeyParamsBuilderError) -> Self {
74 Error::Message(format!("SubkeyParamsBuilderError: {value}"))
75 }
76}
77
78impl From<pgp::composed::SecretKeyParamsBuilderError> for Error {
79 fn from(value: pgp::composed::SecretKeyParamsBuilderError) -> Self {
80 Error::Message(format!("SecretKeyParamsBuilderError: {value}"))
81 }
82}