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
//! Platform-Agnostic Serialized Keys (PASERK) for PASETO.
//!
//! PASERK is a standard format for serializing keys used with PASETO tokens.
//! This crate provides a type-safe, idiomatic Rust implementation of the
//! PASERK specification.
//!
//! # Quick Start
//!
//! ```rust
//! use paserk::core::types::PaserkLocal;
//! use paserk::core::version::K4;
//!
//! // Create a PASERK key from raw bytes
//! let key_bytes: [u8; 32] = [0u8; 32];
//! let paserk_key = PaserkLocal::<K4>::from(key_bytes);
//!
//! // Serialize to PASERK string format
//! let paserk_string = paserk_key.to_string();
//! assert!(paserk_string.starts_with("k4.local."));
//!
//! // Parse a PASERK string back to a key
//! let parsed = PaserkLocal::<K4>::try_from(paserk_string.as_str());
//! assert!(parsed.is_ok());
//! ```
//!
//! # PASERK Types
//!
//! All PASERK key types are implemented for all versions (K1-K4):
//!
//! | Type | Format | Description | K1 | K2 | K3 | K4 |
//! |------|--------|-------------|----|----|----|----|
//! | `local` | `k{v}.local.{data}` | Symmetric encryption key | ✅ | ✅ | ✅ | ✅ |
//! | `public` | `k{v}.public.{data}` | Public verification key | ✅ | ✅ | ✅ | ✅ |
//! | `secret` | `k{v}.secret.{data}` | Secret signing key | N/A¹ | ✅ | ✅ | ✅ |
//! | `lid` | `k{v}.lid.{data}` | Local key identifier | ✅ | ✅ | ✅ | ✅ |
//! | `pid` | `k{v}.pid.{data}` | Public key identifier | ✅ | ✅ | ✅ | ✅ |
//! | `sid` | `k{v}.sid.{data}` | Secret key identifier | N/A¹ | ✅ | ✅ | ✅ |
//! | `local-wrap` | `k{v}.local-wrap.pie.{data}` | PIE-wrapped symmetric key | ✅ | ✅ | ✅ | ✅ |
//! | `secret-wrap` | `k{v}.secret-wrap.pie.{data}` | PIE-wrapped secret key | N/A¹ | ✅ | ✅ | ✅ |
//! | `local-pw` | `k{v}.local-pw.{data}` | Password-wrapped symmetric key | ✅ | ✅ | ✅ | ✅ |
//! | `secret-pw` | `k{v}.secret-pw.{data}` | Password-wrapped secret key | N/A¹ | ✅ | ✅ | ✅ |
//! | `seal` | `k{v}.seal.{data}` | PKE-encrypted symmetric key | ✅ | ✅ | ✅ | ✅ |
//!
//! ¹ K1 uses RSA which has no separate secret key type in PASETO V1.
//!
//! # Versions
//!
//! PASERK supports four versions, corresponding to PASETO versions:
//!
//! | Version | Algorithms | Status |
//! |---------|------------|--------|
//! | **K1** | RSA + AES-CTR + HMAC-SHA384 | ⚠️ **Deprecated** (see warning below) |
//! | **K2** | Ed25519 + `XChaCha20` + `BLAKE2b` | ✅ Fully implemented |
//! | **K3** | P-384 + AES-CTR + HMAC-SHA384 | ✅ Fully implemented |
//! | **K4** | Ed25519 + `XChaCha20` + `BLAKE2b` | ✅ Fully implemented (Recommended) |
//!
//! # ⚠️ Security Warning: K1 (RSA) Vulnerability
//!
//! **The `k1-insecure` feature uses the `rsa` crate which is vulnerable to
//! [RUSTSEC-2023-0071] (Marvin Attack), a timing side-channel attack that
//! could enable private key recovery.**
//!
//! - **Do not use K1 for new projects.** Use [`K4`] instead.
//! - K1 support is provided only for legacy PASETO V1 interoperability.
//! - The feature has been renamed from `k1` to `k1-insecure` to require explicit opt-in.
//! - K1 types will emit deprecation warnings when used.
//!
//! [RUSTSEC-2023-0071]: https://rustsec.org/advisories/RUSTSEC-2023-0071
//!
//! # Features
//!
//! Enable specific versions with feature flags:
//!
//! ```toml
//! [dependencies]
//! paserk = { version = "0.1", features = ["k4"] } # K4 only (default, recommended)
//! paserk = { version = "0.1", features = ["k2", "k4"] } # K2 and K4
//! paserk = { version = "0.1", features = ["all-versions"] } # All versions
//! # paserk = { version = "0.1", features = ["k1-insecure"] } # K1 (⚠️ see security warning)
//! ```
//!
//! # Cryptographic Operations
//!
//! ## Key Wrapping (PIE Protocol)
//!
//! | Version | Encryption | Authentication |
//! |---------|------------|----------------|
//! | K1/K3 | AES-256-CTR | HMAC-SHA384 (48-byte tag) |
//! | K2/K4 | `XChaCha20` | `BLAKE2b` (32-byte tag) |
//!
//! ## Password-Based Key Wrapping (PBKW)
//!
//! | Version | KDF | Encryption | Authentication |
//! |---------|-----|------------|----------------|
//! | K1/K3 | PBKDF2-SHA384 | AES-256-CTR | HMAC-SHA384 |
//! | K2/K4 | Argon2id | `XChaCha20` | `BLAKE2b` |
//!
//! ## Public Key Encryption (Seal)
//!
//! | Version | Key Exchange | Encryption | Authentication |
//! |---------|--------------|------------|----------------|
//! | K1 | RSA-4096 KEM | AES-256-CTR | HMAC-SHA384 |
//! | K2/K4 | X25519 ECDH | `XChaCha20` | `BLAKE2b` |
//! | K3 | P-384 ECDH | AES-256-CTR | HMAC-SHA384 |
//!
//! # Security
//!
//! This crate follows security best practices:
//!
//! - Key material is zeroized on drop
//! - Debug output redacts sensitive key material
//! - Constant-time comparison for secret keys
//! - No unsafe code (`#![forbid(unsafe_code)]`)
//! - Authenticated encryption prevents tampering
//!
//! # Modules
//!
//! - [`core`] - Core types and operations
//! - [`prelude`] - Ergonomic imports (requires `prelude` feature)
//!
//! # Builder Patterns
//!
//! The `prelude` module provides fluent builder APIs for password-based wrapping:
//!
//! ```rust
//! use paserk::prelude::*;
//!
//! # fn main() -> Result<(), paserk::PaserkError> {
//! let key = PaserkLocal::<K4>::from([0x42u8; 32]);
//!
//! // Use preset security profiles
//! let wrapped = LocalPwBuilder::<K4>::moderate()
//! .try_wrap(&key, b"password")?;
//!
//! // Or customize parameters
//! let wrapped = LocalPwBuilder::<K4>::new()
//! .memory_kib(128 * 1024)
//! .iterations(3)
//! .parallelism(2)
//! .try_wrap(&key, b"password")?;
//! # Ok(())
//! # }
//! ```
// Re-export commonly used items at crate root
pub use ;
pub use ;
// Re-export types based on enabled version features
pub use ;
// Re-export wrap protocol markers
pub use ;
// Re-export PBKW parameters
pub use Argon2Params;
// Version-specific type aliases for when only one version is enabled