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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//! # WeCanEncrypt
//!
//! A simple Rust OpenPGP library for encryption, signing, and key management using [rpgp](https://docs.rs/pgp).
//!
//! This library provides a functional API for common OpenPGP operations,
//! including:
//!
//! - **Key Generation**: Create RSA, Curve25519, or NIST curve keys
//! - **Encryption/Decryption**: Encrypt to one or multiple recipients
//! - **Signing/Verification**: Create and verify signatures
//! - **Certificate Management**: Parse, modify, and export certificates
//! - **Key Storage**: SQLite-backed keystore (optional feature)
//!
//! ## Migrating to 0.6.0
//!
//! ### Breaking changes
//!
//! - **`GeneratedKey.secret_key`** is now `Zeroizing<Vec<u8>>` (was `Vec<u8>`).
//! Secret key bytes are securely erased from memory on drop. `Zeroizing`
//! implements `Deref<Target = Vec<u8>>`, so most code works unchanged.
//! If you need a `Vec<u8>`, call `.to_vec()`.
//!
//! - **`CertificateInfo.user_ids`** is now `Vec<UserIDInfo>` (was `Vec<String>`).
//! Each UID now includes `value` (the string), `revoked` (bool), and
//! `certifications` (third-party signatures). Access the UID string via
//! `.value` (e.g., `info.user_ids[0].value`).
//!
//! - **`decrypt_with_key()`** now takes an `allow_legacy: bool` parameter.
//! Pass `false` to reject integrity-unprotected SED packets (recommended).
//! Pass `true` only for historical pre-2007 data.
//!
//! - **`decrypt_bytes()`** no longer decrypts legacy SED packets by default.
//! Use [`decrypt_bytes_legacy()`] for messages without integrity protection.
//!
//! - **Verification now rejects revoked keys.** Signatures from revoked
//! keys or subkeys return `false`. Expired keys can still verify old
//! signatures (by design, per OpenPGP semantics).
//!
//! ## Quick Start
//!
//! ```no_run
//! use wecanencrypt::*;
//!
//! // Generate a new Curve25519 key (fast)
//! let key = create_key_simple("password", &["Alice <alice@example.com>"]).unwrap();
//!
//! // Encrypt a message
//! let ciphertext = encrypt_bytes(key.public_key.as_bytes(), b"Hello!", true).unwrap();
//!
//! // Decrypt it
//! let plaintext = decrypt_bytes(&key.secret_key, &ciphertext, "password").unwrap();
//! assert_eq!(plaintext, b"Hello!");
//! ```
//!
//! ## Cipher Suites
//!
//! The library supports multiple cipher suites:
//!
//! | Suite | Primary Key | Encryption Subkey | Speed |
//! |-------|-------------|-------------------|-------|
//! | `Cv25519` (default) | EdDSA Legacy | ECDH Curve25519 | Fast |
//! | `Cv25519Modern` | Ed25519 (RFC 9580) | X25519 | Fast |
//! | `NistP256` | ECDSA P-256 | ECDH P-256 | Fast |
//! | `NistP384` | ECDSA P-384 | ECDH P-384 | Fast |
//! | `NistP521` | ECDSA P-521 | ECDH P-521 | Fast |
//! | `Rsa2k` | RSA 2048-bit | RSA 2048-bit | Slow |
//! | `Rsa4k` | RSA 4096-bit | RSA 4096-bit | Very Slow |
//!
//! ## Features
//!
//! - `keystore`: Enable SQLite-backed key storage (requires `rusqlite`)
//! - `network`: Enable network operations for fetching keys from keyservers
//!
//! ## Design
//!
//! This library uses a functional API - all operations are standalone functions
//! that take certificate data as `&[u8]`. This provides maximum flexibility
//! and avoids the overhead of wrapper types.
// Re-export rpgp crate
pub use pgp;
// Modules
// Re-export error types
pub use ;
// Re-export all public types
pub use ;
// Re-export parsing functions
pub use ;
// Re-export encryption functions
pub use ;
// Re-export decryption functions
pub use ;
// Re-export signing functions
pub use ;
// Re-export verification functions
pub use ;
// Re-export key generation and management functions
pub use ;
// Re-export keyring functions
pub use ;
// Re-export SSH functions
pub use ;
// Re-export keystore types when feature is enabled
pub use ;
// Re-export network functions when feature is enabled
pub use ;