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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
//! This library provides encryption-based encoding to various text schemes
//! using AES encryption with multiple scheme options.
//!
//! # Quick Start
//!
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! use oboron::{AasvC32, ObtextCodec};
//! let key = oboron::generate_key(); // get key
//! let ob = AasvC32::new(&key)?; // instantiate ObtextCodec (cipher+encoder)
//! let ot = ob.enc("secret data")?; // get obtext (encoded ciphertext)
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! # Parameter Order Convention
//!
//! All functions in this library follow a consistent parameter ordering convention:
//!
//! **`data` < `format` < `key`**
//!
//! - `data` (plaintext/obtext) comes first - it's what you're operating on
//! - `format` comes second (when present) - it's configuration/options
//! - `key` comes last (when present) - it's the security credential
//!
//! Examples:
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! # use oboron;
//! # let key = oboron::generate_key();
//! # let omb = oboron::Omnib::new(&key)?;
//! // Operations: data, format
//! let ot = omb.enc("plaintext", "aasv.b64")?;
//! omb.dec(&ot, "aasv.b64")?;
//!
//! // Constructors: format, key
//! oboron::Ob::new("aasv.b64", &key)?;
//!
//! // Convenience functions: data, format, key
//! # #[cfg(feature = "convenience")]
//! let ot = oboron::enc("plaintext", "aasv.b64", &key)?;
//! # #[cfg(feature = "convenience")]
//! oboron::dec(&ot, "aasv.b64", &key)?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! # Choosing the Right Type
//!
//! Oboron provides several types optimized for different use cases:
//!
//! ## 1. Fixed-Format Types (Fastest, Compile-Time)
//!
//! Use format-specific types when you know the format at compile time:
//!
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! # use oboron::{AasvC32, AasvB64, ObtextCodec};
//! # let key = oboron::generate_key();
//! let aasv = AasvC32::new(&key)?; // aasv.c32 format (Crockford base32)
//! let aasv_b64 = AasvB64::new(&key)?; // aasv.b64 format (base64url)
//!
//! let ot = aasv.enc("hello")?;
//! let pt2 = aasv.dec(&ot)?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! - Use case: Format is known at compile time
//! - Performance: Fastest (zero overhead)
//! - Flexibility: Format fixed, explicit in type name
//!
//! ## 2. `Ob` - Runtime Format (Flexible)
//!
//! Use `Ob` when you need to choose the format at runtime:
//!
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! # use oboron::{Ob, ObtextCodec};
//! # let key = oboron::generate_key();
//! // Format chosen at runtime
//! let mut ob = Ob::new("aasv.b64", &key)?;
//!
//! let ot = ob.enc("hello")?;
//! let pt2 = ob.dec(&ot)?;
//!
//! // Can change format if needed
//! ob.set_format("aasv.hex")?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! - Use case: Format determined at runtime (config, user input)
//! - Performance: Near-zero overhead (inlines to static functions)
//! - Flexibility: Runtime format selection, can be changed after construction
//!
//! ## 3. `Omnib` - Multi-Format Operations
//!
//! Use `Omnib` when working with different formats in a single context:
//!
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! # use oboron::Omnib;
//! # let key = oboron::generate_key();
//! let omb = Omnib::new(&key)?;
//!
//! // Encode to different formats
//! let ot_b32 = omb.enc("data", "aasv.c32")?;
//! let ot_b64 = omb.enc("data", "aasv.b64")?;
//! let ot_hex = omb.enc("data", "aasv.hex")?;
//!
//! // Decode with automatic format detection
//! let pt2 = omb.autodec(&ot_b64)?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! - Use case: Working with multiple formats or unknown formats
//! - Performance: Small overhead (format parsing per operation)
//! - Flexibility: Maximum - handles any format, autodetects on dec
//!
//! # Quick Reference
//!
//! | Type | Format | Use Case | Performance |
//! |-----------------|--------------------|-------------------|---------------------|
//! | `AasvC32`, etc. | Compile-time | Known format | Fastest (zero-cost) |
//! | `Ob` | Runtime, mutable | Config-driven | Near-zero overhead |
//! | `Omnib` | Per-operation | Multiple formats | Small overhead |
//!
//! # Typical Production Usage: Fixed ObtextCodec
//!
//! Best performance and type safety for multiple operations with the same format:
//!
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(all(feature = "aasv", feature = "apgs"))]
//! # {
//! # use oboron::ObtextCodec;
//! # use oboron;
//! # let key = oboron::generate_key();
//! // Fixed format types (best performance for multiple operations with same format)
//! let aasv = oboron::AasvC32::new(&key)?; // "aasv.c32" fixed-format ObtextCodec instance
//! let apgs = oboron::ApgsC32::new(&key)?; // "apgs.c32" fixed-format ObtextCodec instance
//!
//! let ot_aasv = aasv.enc("data1")?;
//! let ot_apgs = apgs.enc("data2")?;
//!
//! // Decoding
//! let pt1 = aasv.dec(&ot_aasv)?; // Decodes successfully
//! let pt2 = apgs.dec(&ot_apgs)?;
//! assert_eq!(pt1, "data1");
//! assert_eq!(pt2, "data2");
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! # Encryption Schemes
//!
//! - Authenticated:
//! - `Aags`: deterministic AES-GCM-SIV
//! - `Aasv`: deterministic AES-SIV (nonce-misuse resistant)
//! - `Apgs`: probabilistic AES-GCM-SIV
//! - `Apsv`: probabilistic AES-SIV
//! - Un-authenticated:
//! - `Upbc`: probabilistic AES-CBC
//! - Insecure (obfuscation only):
//! - `Zrbcx`: deterministic AES-CBC with constant IV
//!
//! Testing/Demo only schemes using no encryption (`mock` feature group):
//! - `Mock1`: Identity
//! - `Mock2`: Reverse plaintext
//!
//! Each scheme supports four string encodings:
//! - B64 - URL-safe base64 (RFC 4648 base64url standard)
//! - B32 - Standard base32 (RFC 4648)
//! - C32 - Crockford base32
//! - Hex - Hexadecimal
//!
//! # The `ObtextCodec` Trait
//!
//! All types (`Ob`, `AasvC32`, `ApsvB64`, etc.) except `Omnib` implement the `ObtextCodec` trait,
//! ```rust
//! # fn main() -> Result<(), oboron::Error> {
//! # #[cfg(feature = "aasv")]
//! # {
//! # use oboron::{ObtextCodec, AasvC32, Ob};
//! # let key = oboron::generate_key();
//! fn process<O: ObtextCodec>(ob: &O, data: &str) -> Result<String, oboron::Error> {
//! let ot = ob.enc(data)?;
//! ob.dec(&ot)
//! }
//!
//! let aasv = AasvC32::new(&key)?;
//! let ob = Ob::new("aasv.c32", &key)?;
//!
//! process(&aasv, "hello")?;
//! process(&ob, "hello")?;
//! # }
//! # Ok(())
//! # }
//! ```
//!
//! The `ObtextCodec` trait is automatically imported via the prelude.
// Re-export public types and constants
pub use ;
pub use Error;
pub use MasterKey;
// Re-export from obcrypt
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Testing
pub use ;
pub use ;
pub use ;
pub use generate_key;
pub use generate_key_bytes;
pub use generate_key_hex;
pub use generate_secret;
pub use generate_secret_bytes;
pub use generate_secret_hex;
// Re-export core types
pub use Encoding;
pub use Format;
pub use Scheme;
// Re-export Ob
pub use Ob;
// Factory functions
pub use ;
pub use ;
pub use ;
pub use ;
// Conditionally export format string constants (scheme+encoding combinations)
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Legacy
pub use *;
// Testing
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Legacy
pub use *;
// Testing
pub use *;
pub use *;
// Conditionally export format-specific structs (scheme+encoding combinations)
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Testing
pub use ;
pub use ;
// Re-export multi-format Oboron implementation
pub use Omnib;
/// Convenience prelude for common imports.
///
/// Import everything you need with:
/// ```rust
/// use oboron::prelude::*;
/// ```
// ============================================================================
// Convenience Functions
// ============================================================================
//
// All convenience functions follow the parameter order convention:
// data < format < key
//
// This ensures consistency across the API:
// - Data (plaintext/obtext) always comes first
// - Format specification comes second (when present)
// - Key comes last (when present)
// ============================================================================
/// Encrypt+encode plaintext with a specified format.
///
/// This is a convenience wrapper around [`Omnib::enc`].
/// For repeated operations, consider creating an [`Omnib`] instance directly.
///
/// # Parameter Order
/// `(data, format, key)` - follows the convention: data < format < key
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # {
/// # use oboron;
/// # let key = oboron::generate_key();
/// let ot = oboron::enc("secret data", "aasv.b64", &key)?;
/// # }
/// # Ok(())
/// # }
/// ```
/// Encrypt+encode plaintext with a specified format using the hardcoded key (testing only).
///
/// # Parameter Order
/// `(data, format)` - key is implicit (hardcoded key)
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # {
/// # use oboron;
/// let ot = oboron::enc_keyless("test data", "aasv.b64")?;
/// # }
/// # Ok(())
/// # }
/// ```
/// Decode+decrypt obtext with a specified format.
///
/// This is a convenience wrapper around [`Omnib::dec`].
/// For repeated operations, consider creating an [`Omnib`] instance directly.
///
/// # Parameter Order
/// `(data, format, key)` - follows the convention: data < format < key
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # use oboron;
/// # {
/// # let key = oboron::generate_key();
/// # let ot = oboron::enc("test123", "aasv.b64", &key)?;
/// let pt2 = oboron::dec(&ot, "aasv.b64", &key)?;
/// # assert_eq!(pt2, "test123");
/// # }
/// # Ok(())
/// # }
/// ```
/// Decode+decrypt obtext with a specified format using the hardcoded key (testing only).
///
/// # Parameter Order
/// `(data, format)` - key is implicit (hardcoded key)
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # {
/// # use oboron;
/// # let ot = oboron::enc_keyless("test", "aasv.b64")?;
/// let pt2 = oboron::dec_keyless(&ot, "aasv.b64")?;
/// # assert_eq!(pt2, "test");
/// # }
/// # Ok(())
/// # }
/// ```
/// Decode+decrypt obtext with automatic format detection.
///
/// Automatically detects both the scheme and encoding used.
/// This is a convenience wrapper around [`Omnib::autodec`].
///
/// # Parameter Order
/// `(data, key)` - format is autodetected
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # {
/// # use oboron;
/// # let key = oboron::generate_key();
/// # let ot = oboron::enc("secret", "aasv.b64", &key)?;
/// let pt2 = oboron::autodec(&ot, &key)?; // Format autodetected, including encoding
/// # assert_eq!(pt2, "secret");
/// # }
/// # Ok(())
/// # }
/// ```
/// Decode+decrypt obtext with automatic format detection using the hardcoded key (testing only).
///
/// # Parameter Order
/// `(data)` - both format and key are implicit
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), oboron::Error> {
/// # #[cfg(feature = "aasv")]
/// # {
/// # use oboron;
/// # let ot = oboron::enc_keyless("test", "mock1.b64")?;
/// let pt2 = oboron::autodec_keyless(&ot)?; // Autodetect format; use hardcoded key
/// # assert_eq!(pt2, "test");
/// # }
/// # Ok(())
/// # }
/// ```