simple_x509/lib.rs
1//! # Overview
2//!
3//! This is a simple library for creating and parsing X509 certificates.
4//!
5//! A Library featuring:
6//!
7//! - Build X509 certificates
8//! - Encode certificates to DER format
9//! - Signing with external crypto function
10//! - Decoding of X509 certificates from DER format
11//! - Verifying with external crypto function
12//! - Encoding/decoding operations for frequently using extensions
13//!
14//! ## Usage
15//!
16//! Create and verify self-signed CA certificate
17//!
18//! ```no_run
19//! use simple_x509::*;
20//!
21//! fn sign_fn(data: &[u8], sign_key: &[u8]) -> Option<Vec<u8>> {
22//!
23//! // Signing implementation ...
24//!
25//! Some(Vec::new())
26//! }
27//!
28//! fn verify_fn(pub_key: &[u8], data: &[u8], sign: &[u8]) -> Option<bool> {
29//!
30//! // Verify implementation ...
31//!
32//! Some(true)
33//! }
34//!
35//! fn main() {
36//! let country = "AU";
37//! let state = "Some-State";
38//! let organization = "Internet Widgits Pty Ltd";
39//!
40//! // Load Public Key
41//! let pub_key = std::fs::read("rsa_pub.der").unwrap();
42//!
43//! // Build X509 structure
44//! let x = X509Builder::new(vec![0xf2, 0xf9, 0xd8, 0x03, 0xd7, 0xb7, 0xd7, 0x34]) /* SerialNumber */
45//! .version(2)
46//! .issuer_prstr(vec![2, 5, 4, 6], country) /* countryName */
47//! .issuer_utf8(vec![2, 5, 4, 8], state) /* stateOrProvinceName */
48//! .issuer_utf8(vec![2, 5, 4, 10], organization) /* organizationName */
49//! .subject_prstr(vec![2, 5, 4, 6], country) /* countryName */
50//! .subject_utf8(vec![2, 5, 4, 8], state) /* stateOrProvinceName */
51//! .subject_utf8(vec![2, 5, 4, 10], organization) /* organizationName */
52//! .not_before_utc(1_619_014_703)
53//! .not_after_utc(1_650_550_703)
54//! .pub_key_der(&pub_key)
55//! .sign_oid(vec![1, 2, 840, 113549, 1, 1, 11]) /* sha256WithRSAEncryption (PKCS #1) */
56//! .build();
57//!
58//! // Load Signing Key
59//! let sign_key = std::fs::read("rsa.pkcs8").unwrap();
60//!
61//! // Signing a certificate with external function
62//! let cert = x.sign(sign_fn, &sign_key).expect("Signing failed");
63//!
64//! // Encode to DER format
65//! let der = cert.x509_enc().expect("x509_enc() failed");
66//!
67//! // Decode
68//! let x2 = der.x509_dec().expect("Failed to deserialize");
69//!
70//! // Getting Public Key in DER format from certificate
71//! let pub_key2 = x2.pub_key().expect("Failed to get Public Key");
72//!
73//! // Verify signature with external function
74//! let res = x2.verify(verify_fn, &pub_key2);
75//! }
76//! ```
77
78pub mod error;
79pub mod ext;
80pub mod x509;
81
82pub use error::*;
83pub use ext::*;
84pub use x509::*;