sharpie/lib.rs
1//! Sign and verify using _RSA_ or _ED25519_ with a focus on simplicity.
2//!
3//! Use a simple interface: `sign` or `verify`,
4//! from either the [ed] or [rsa] modules supporting multiple key formats.
5//!
6//! To sign:
7//!
8//! 1. Get the key bytes using `PrivateKey::<type>(..source..).read()`
9//! 2. Optionally, cache these bytes for reuse
10//! 3. Use `sign`
11//!
12//! To verify:
13//!
14//! 1. Get the key bytes using `PublicKey::<type>(..source..).read()`
15//! 2. Optionally, cache these bytes for reuse
16//! 3. Use `verify`
17//!
18//! Here's a full sign-verify cycle using `ED25519`, with keys generated using OpenSSL in this way:
19//!
20//! ```ignore
21//! $ openssl genpkey -algorithm ED25519 -out ed.private.pem
22//! $ openssl pkey -in private-key-ed.pem -pubout -out ed.public.pem
23//! ```
24//! Sign and verify using [sharpie::ed](ed):
25//!
26//! ```ignore
27#![doc = include_str!("../examples/sign.rs")]
28//! ```
29//!
30//!
31//!
32///ED25519 signing and verification
33pub mod ed;
34
35/// RSA signing and verification
36pub mod rsa;
37
38use snafu::prelude::*;
39
40#[derive(Debug, Snafu)]
41pub enum Error {
42 #[snafu(display("Unable to parse PEM: {}", source))]
43 InvalidPem { source: pem::PemError },
44 #[snafu(display("Signature operation failed"))]
45 SignatureFailed { source: ring::error::Unspecified },
46 #[cfg(feature = "base64")]
47 #[snafu(display("Decoding data failed"))]
48 DecodeFailed { source: base64::DecodeError },
49 #[snafu(display("Cannot read key: {}", source))]
50 InvalidKey { source: ring::error::KeyRejected },
51}
52type Result<T, E = Error> = std::result::Result<T, E>;