tsumiki_pkcs/lib.rs
1//! # tsumiki-pkcs
2//!
3//! PKCS (Public Key Cryptography Standards) implementation.
4//!
5//! This crate provides support for multiple PKCS standards:
6//!
7//! ## Supported Standards
8//!
9//! - **PKCS#1** ([RFC 8017](https://datatracker.ietf.org/doc/html/rfc8017)) - RSA key format
10//! - **PKCS#8** ([RFC 5958](https://datatracker.ietf.org/doc/html/rfc5958)) - Generic private key format
11//! - **PKCS#9** ([RFC 2985](https://datatracker.ietf.org/doc/html/rfc2985)) - Selected attributes
12//! - **SEC1** ([RFC 5915](https://datatracker.ietf.org/doc/html/rfc5915)) - EC private key format
13//!
14//! ## Key Features
15//!
16//! - Unified `PrivateKey` enum for all key formats
17//! - Auto-detection of key format from PEM
18//! - Type-safe key inspection (algorithm, size, etc.)
19//! - rustls integration (with `rustls` feature)
20//!
21//! ## Example
22//!
23//! ```no_run
24//! use std::str::FromStr;
25//! use tsumiki_pem::Pem;
26//! use tsumiki::decoder::Decoder;
27//! use tsumiki_pkcs::{PrivateKey, PrivateKeyExt};
28//!
29//! // PKCS#8 EC private key (P-256)
30//! let pem_data = "-----BEGIN PRIVATE KEY-----
31//! MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
32//! OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
33//! 1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
34//! -----END PRIVATE KEY-----";
35//!
36//! let pem = Pem::from_str(pem_data).unwrap();
37//! let key: PrivateKey = pem.decode().unwrap();
38//!
39//! // Inspect key properties
40//! println!("Algorithm: {}", key.algorithm());
41//! println!("Key size: {} bits", key.key_size());
42//! ```
43//!
44//! ## rustls Integration
45//!
46//! With the `rustls` feature enabled, you can convert between rustls and tsumiki key types:
47//!
48//! ```ignore
49//! use rustls_pki_types::PrivateKeyDer;
50//! use tsumiki_pkcs::PrivateKey;
51//!
52//! // Convert rustls key to tsumiki
53//! let rustls_key: PrivateKeyDer = /* load from file */;
54//! let tsumiki_key = PrivateKey::try_from(rustls_key)?;
55//!
56//! // Convert back to rustls
57//! let rustls_key: PrivateKeyDer = tsumiki_key.try_into()?;
58//! ```
59
60#![forbid(unsafe_code)]
61
62pub mod error;
63pub mod pkcs1;
64pub mod pkcs8;
65pub mod pkcs9;
66mod private_key;
67mod public_key;
68#[cfg(feature = "rustls")]
69pub mod rustls;
70pub mod sec1;
71
72pub use error::{Error, Result};
73pub use private_key::{KeyAlgorithm, PrivateKey, PrivateKeyExt};
74pub use public_key::{PublicKey, PublicKeyExt};