Skip to main content

kernoid_e2e/
lib.rs

1// SPDX-License-Identifier: MIT
2//! End-to-end encryption of kernoid's apps (RFC 0006): an account's OpenPGP key and the protected copies of its
3//! secret key (`keys`), encrypting and decrypting data (`message`), mail as PGP/MIME with header protection and the
4//! summary the apps show in lists (`mime`), and mail built and read in the client (`compose`). All of the
5//! cryptography is rpgp; nothing here is cryptography of its own.
6
7pub mod compose;
8pub mod keys;
9pub mod message;
10pub mod mime;
11#[cfg(feature = "wasm")]
12mod wasm;
13
14pub use keys::{Kind, PublicKey, SecretKey};
15
16/// What can go wrong. Decryption failures are one `Decrypt` – which key or packet failed is not for the user.
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19    #[error("not an OpenPGP key: {0}")]
20    Key(String),
21    #[error("the key has no usable subkey for encryption")]
22    NoEncryptionKey,
23    #[error("wrong passphrase, or the protected key is damaged")]
24    Unlock,
25    #[error("cannot decrypt the message with these keys")]
26    Decrypt,
27    #[error("not an encrypted message")]
28    NotEncrypted,
29    #[error("not a mail message")]
30    NotMail,
31    #[error("OpenPGP: {0}")]
32    Pgp(String),
33}
34
35impl From<pgp::errors::Error> for Error {
36    fn from(error: pgp::errors::Error) -> Self {
37        Error::Pgp(error.to_string())
38    }
39}
40
41pub type Result<T> = std::result::Result<T, Error>;