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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
//! `uselesskey` generates *runtime* key fixtures for tests.
//!
//! The point is operational, not cryptographic:
//! keep secrets-shaped blobs out of your git history while still testing against
//! "real-shaped" inputs (PKCS#8 PEM/DER, SPKI, etc.).
//!
//! > Not for production. Deterministic keys are predictable by design.
//!
//! For integration with third-party crypto crates, see the adapter crates:
//! `uselesskey-jsonwebtoken`, `uselesskey-rustls`, `uselesskey-tonic`,
//! `uselesskey-ring`, `uselesskey-rustcrypto`, and `uselesskey-aws-lc-rs`.
//!
//! # Feature Selection
//!
//! The facade default feature set is empty. A bare `uselesskey` dependency gives
//! you core types like [`Factory`], [`Mode`], and [`Seed`]; enable only the
//! fixture families you need.
//!
//! Token-only consumers can keep the facade lightweight:
//!
//! ```toml
//! [dev-dependencies]
//! uselesskey = { version = "0.6.0", default-features = false, features = ["token"] }
//! ```
//!
//! ```
//! # #[cfg(feature = "token")]
//! # fn main() {
//! use uselesskey::{Factory, TokenFactoryExt, TokenSpec};
//!
//! let fx = Factory::deterministic_from_str("api-key-fixtures");
//! let token = fx.token("svc-api", TokenSpec::api_key());
//! assert!(token.value().starts_with("uk_test_"));
//! # }
//! # #[cfg(not(feature = "token"))]
//! # fn main() {}
//! ```
//!
//! Entropy-only consumers can stay even smaller:
//!
//! ```toml
//! [dev-dependencies]
//! uselesskey = { version = "0.6.0", default-features = false, features = ["entropy"] }
//! ```
//!
//! ```
//! # #[cfg(feature = "entropy")]
//! # fn main() {
//! use uselesskey::{EntropyFactoryExt, Factory};
//!
//! let fx = Factory::deterministic_from_str("entropy-fixtures");
//! let bytes = fx.entropy("scan-fixture").bytes(32);
//! assert_eq!(bytes.len(), 32);
//! # }
//! # #[cfg(not(feature = "entropy"))]
//! # fn main() {}
//! ```
//!
//! # Quick Start
//!
//! If you enable `rsa`, create a factory and generate RSA key fixtures:
//!
//! ```
//! # #[cfg(feature = "rsa")]
//! # fn main() {
//! use uselesskey::{Factory, RsaFactoryExt, RsaSpec};
//!
//! // Random mode: each run produces different keys (still cached per-factory)
//! let fx = Factory::random();
//! let keypair = fx.rsa("my-service", RsaSpec::rs256());
//!
//! // Access keys in various formats
//! let pem = keypair.private_key_pkcs8_pem();
//! let der = keypair.private_key_pkcs8_der();
//! let pub_pem = keypair.public_key_spki_pem();
//!
//! assert!(pem.contains("-----BEGIN PRIVATE KEY-----"));
//! assert!(!der.is_empty());
//! # }
//! # #[cfg(not(feature = "rsa"))]
//! # fn main() {}
//! ```
//!
//! # Deterministic Mode
//!
//! For reproducible test fixtures, use deterministic mode with a seed:
//!
//! ```
//! # #[cfg(feature = "rsa")]
//! # fn main() {
//! use uselesskey::{Factory, RsaFactoryExt, RsaSpec};
//!
//! // Create a deterministic factory from stable text
//! let fx = Factory::deterministic_from_str("test-seed");
//!
//! // Same seed + same label + same spec = same key, regardless of call order
//! let key1 = fx.rsa("issuer", RsaSpec::rs256());
//! let key2 = fx.rsa("issuer", RsaSpec::rs256());
//!
//! assert_eq!(key1.private_key_pkcs8_pem(), key2.private_key_pkcs8_pem());
//! # }
//! # #[cfg(not(feature = "rsa"))]
//! # fn main() {}
//! ```
//!
//! # Environment-Based Seeds
//!
//! In CI, you often want to read the seed from an environment variable:
//!
//! ```
//! use uselesskey::Factory;
//!
//! // This reads from the environment variable and parses the seed
//! // Returns Err if the variable is not set
//! # unsafe { std::env::set_var("USELESSKEY_SEED", "ci-build-12345") };
//! let fx = Factory::deterministic_from_env("USELESSKEY_SEED").unwrap();
//! # unsafe { std::env::remove_var("USELESSKEY_SEED") };
//! ```
//!
//! # Negative Fixtures
//!
//! Test error handling with intentionally corrupted keys:
//!
//! ```
//! # #[cfg(feature = "rsa")]
//! # fn main() {
//! use uselesskey::{Factory, RsaFactoryExt, RsaSpec};
//! use uselesskey::negative::CorruptPem;
//!
//! let fx = Factory::random();
//! let keypair = fx.rsa("test", RsaSpec::rs256());
//!
//! // Get a PEM with a corrupted header
//! let bad_pem = keypair.private_key_pkcs8_pem_corrupt(CorruptPem::BadHeader);
//! assert!(bad_pem.contains("-----BEGIN CORRUPTED KEY-----"));
//!
//! // Get truncated DER bytes
//! let truncated = keypair.private_key_pkcs8_der_truncated(10);
//! assert_eq!(truncated.len(), 10);
//!
//! // Get a mismatched public key (valid but doesn't match the private key)
//! let mismatched = keypair.mismatched_public_key_spki_der();
//! assert!(!mismatched.is_empty());
//! # }
//! # #[cfg(not(feature = "rsa"))]
//! # fn main() {}
//! ```
//!
//! # Temporary Files
//!
//! Some libraries require file paths. Use `write_*` methods which return
//! [`TempArtifact`]:
//!
//! ```
//! # #[cfg(feature = "rsa")]
//! # fn main() {
//! use uselesskey::{Factory, RsaFactoryExt, RsaSpec, TempArtifact};
//!
//! let fx = Factory::random();
//! let keypair = fx.rsa("server", RsaSpec::rs256());
//!
//! // Write to a tempfile (auto-cleaned on drop)
//! let temp: TempArtifact = keypair.write_private_key_pkcs8_pem().unwrap();
//! let path = temp.path();
//!
//! assert!(path.exists());
//! // Pass `path` to libraries that need file paths
//! # }
//! # #[cfg(not(feature = "rsa"))]
//! # fn main() {}
//! ```
//!
//! # JWK Support
//!
//! With the `jwk` feature, generate JSON Web Keys:
//!
//! ```
//! # #[cfg(all(feature = "jwk", feature = "rsa"))]
//! # fn main() {
//! use uselesskey::{Factory, RsaFactoryExt, RsaSpec};
//!
//! let fx = Factory::random();
//! let keypair = fx.rsa("auth", RsaSpec::rs256());
//!
//! // Get a stable key ID
//! let kid = keypair.kid();
//!
//! // Get the public JWK
//! let jwk = keypair.public_jwk();
//! let jwk_value = jwk.to_value();
//! assert_eq!(jwk_value["kty"], "RSA");
//! assert_eq!(jwk_value["alg"], "RS256");
//!
//! // Get a JWKS containing one key
//! let jwks = keypair.public_jwks();
//! let jwks_value = jwks.to_value();
//! assert!(jwks_value["keys"].is_array());
//! # }
//! # #[cfg(not(all(feature = "jwk", feature = "rsa")))]
//! # fn main() {}
//! ```
//!
//! # X.509 Certificates
//!
//! With the `x509` feature, generate self-signed certificates and certificate chains:
//!
//! ```
//! # #[cfg(feature = "x509")]
//! # fn main() {
//! use uselesskey::{Factory, X509FactoryExt, X509Spec};
//!
//! let fx = Factory::random();
//! let cert = fx.x509_self_signed("my-service", X509Spec::self_signed("localhost"));
//!
//! assert!(cert.cert_pem().contains("BEGIN CERTIFICATE"));
//! assert!(!cert.cert_der().is_empty());
//! assert!(!cert.private_key_pkcs8_der().is_empty());
//! # }
//! # #[cfg(not(feature = "x509"))]
//! # fn main() {}
//! ```
//!
//! # X.509 Certificate Chains
//!
//! With the `x509` feature, generate a TLS-style certificate chain and negative
//! variants for error-path tests:
//!
//! ```
//! # #[cfg(feature = "x509")]
//! # fn main() {
//! use uselesskey::{ChainSpec, Factory, X509FactoryExt};
//!
//! let fx = Factory::random();
//! let chain = fx.x509_chain("svc", ChainSpec::new("test.example.com"));
//!
//! assert!(chain.chain_pem().contains("BEGIN CERTIFICATE"));
//! assert!(chain.root_cert_pem().contains("BEGIN CERTIFICATE"));
//! assert!(chain.leaf_private_key_pkcs8_pem().contains("BEGIN PRIVATE KEY"));
//!
//! let revoked = chain.revoked_leaf();
//! assert!(revoked.crl_pem().is_some());
//! # }
//! # #[cfg(not(feature = "x509"))]
//! # fn main() {}
//! ```
//!
//! # Features
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `rsa` | RSA key fixtures |
//! | `ecdsa` | ECDSA P-256/P-384 key fixtures |
//! | `ed25519` | Ed25519 key fixtures |
//! | `hmac` | HMAC secret fixtures |
//! | `entropy` | Deterministic high-entropy byte fixtures |
//! | `token` | API key/bearer token fixtures |
//! | `ssh` | OpenSSH key and cert fixtures |
//! | `webhook` | Webhook signature fixtures (GitHub/Stripe/Slack) |
//! | `pgp` | OpenPGP key fixtures |
//! | `x509` | X.509 certificate and chain fixtures |
//! | `jwk` | JWK/JWKS output for all key types |
//! | `all-keys` | All key types (rsa + ecdsa + ed25519 + hmac + pgp) |
//! | `full` | Everything: all-keys + token + x509 + jwk |
//!
//! The default feature set is empty; opt into the algorithms or fixture families
//! your tests actually need.
// ---------------------------------------------------------------------------
// Core re-exports
// ---------------------------------------------------------------------------
pub use TempArtifact;
pub use ;
/// Generic negative-fixture helpers (corrupt PEM, truncate DER, etc.).
// ---------------------------------------------------------------------------
// JWK support
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Key type re-exports (feature-gated)
// ---------------------------------------------------------------------------
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Common imports for tests.
///
/// Re-exports vary based on enabled features. For example, with
/// `features = ["rsa"]`:
/// ```
/// use uselesskey::prelude::*;
/// // Gives you: Factory, Mode, Seed, TempArtifact, RsaFactoryExt, RsaSpec, RsaKeyPair, negative::*
/// ```