rust_bottle/
lib.rs

1//! # rust-bottle
2//!
3//! Rust implementation of the Bottle protocol - layered message containers
4//! with encryption and signatures.
5//!
6//! This library provides functionality similar to [gobottle](https://github.com/BottleFmt/gobottle),
7//! including support for multiple key types, IDCards, Keychains, and Memberships.
8//!
9//! ## Overview
10//!
11//! The Bottle protocol provides a secure way to package messages with multiple layers
12//! of encryption and signatures. Each encryption layer can target a different recipient,
13//! and multiple signers can sign the same bottle. This enables complex security
14//! scenarios like group messaging, multi-party encryption, and verifiable data
15//! structures.
16//!
17//! ## Core Concepts
18//!
19//! - **Bottles**: Layered message containers that support multiple encryption and signature layers
20//! - **IDCards**: Declarations of keys with specific purposes (sign, decrypt) and lifecycle management
21//! - **Keychains**: Secure storage for private keys, indexed by public key fingerprints
22//! - **Memberships**: Cryptographically signed group affiliations with role information
23//!
24//! ## Example
25//!
26//! ```rust
27//! use rust_bottle::*;
28//! use rand::rngs::OsRng;
29//!
30//! // Create and encrypt a message
31//! let message = b"Hello, Bottle!";
32//! let mut bottle = Bottle::new(message.to_vec());
33//!
34//! let rng = &mut OsRng;
35//! let key = X25519Key::generate(rng);
36//! bottle.encrypt(rng, &key.public_key_bytes()).unwrap();
37//!
38//! // Decrypt
39//! let opener = Opener::new();
40//! let decrypted = opener.open(&bottle, Some(&key.private_key_bytes())).unwrap();
41//! assert_eq!(decrypted, message);
42//! ```
43
44pub mod bottle;
45pub mod ecdh;
46pub mod errors;
47pub mod hash;
48pub mod idcard;
49pub mod keychain;
50pub mod keys;
51pub mod membership;
52pub mod pkix;
53pub mod signing;
54pub mod tpm;
55pub mod utils;
56
57/// Core bottle types for message containers
58pub use bottle::{Bottle, Opener};
59
60/// Error types and result aliases
61pub use errors::{BottleError, Result};
62
63/// IDCard for key management
64pub use idcard::IDCard;
65
66/// Keychain for secure key storage
67pub use keychain::Keychain;
68
69/// Membership for group affiliations
70pub use membership::Membership;
71
72/// Signing and verification traits
73pub use signing::{Sign, Verify};
74
75/// ECDH encryption and decryption functions
76pub use ecdh::{
77    ecdh_decrypt, ecdh_decrypt_with_handler, ecdh_encrypt, ecdh_encrypt_with_handler, rsa_decrypt,
78    rsa_encrypt, ECDHDecrypt, ECDHEncrypt,
79};
80
81/// Post-quantum encryption functions (requires `ml-kem` feature)
82#[cfg(feature = "ml-kem")]
83pub use ecdh::{
84    hybrid_decrypt_mlkem768_x25519, hybrid_encrypt_mlkem768_x25519, mlkem1024_decrypt,
85    mlkem1024_encrypt, mlkem768_decrypt, mlkem768_encrypt,
86};
87
88/// Cryptographic key types (classical)
89pub use keys::{EcdsaP256Key, Ed25519Key, RsaKey, X25519Key};
90
91/// Post-quantum signature key types (requires `post-quantum` feature)
92#[cfg(feature = "post-quantum")]
93pub use keys::{
94    MlDsa44Key, MlDsa65Key, MlDsa87Key,
95    SlhDsa128sKey, SlhDsa128fKey, SlhDsa192sKey, SlhDsa192fKey, SlhDsa256sKey, SlhDsa256fKey,
96    SlhDsaSha2_128sKey, SlhDsaSha2_128fKey, SlhDsaSha2_192sKey, SlhDsaSha2_192fKey, SlhDsaSha2_256sKey, SlhDsaSha2_256fKey,
97};
98
99/// Post-quantum encryption key types (requires `ml-kem` feature)
100#[cfg(feature = "ml-kem")]
101pub use keys::{MlKem1024Key, MlKem768Key};
102
103/// PKIX/PKCS#8 key serialization
104pub use pkix::{
105    marshal_pkcs8_private_key, marshal_pkcs8_private_key_pem, marshal_pkix_public_key,
106    marshal_pkix_public_key_pem, marshal_pkix_public_key_with_type, parse_pkcs8_private_key,
107    parse_pkcs8_private_key_pem, parse_pkix_public_key, parse_pkix_public_key_pem, KeyType,
108};
109
110/// Utility functions
111pub use utils::{decrypt_short_buffer, encrypt_short_buffer, mem_clr};
112
113/// TPM/HSM support (requires `tpm` feature)
114#[cfg(feature = "tpm")]
115pub use tpm::{ECDHHandler, TpmHandler};