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
//! Pure Rust implementation of Public-Key Cryptography Standards (PKCS) #8:
//! Private-Key Information Syntax Specification (as defined in [RFC 5208]).
//!
//! # About
//!
//! This is a minimalistic library targeting `no_std` platforms and small code
//! size. It supports decoding/encoding of the following types without the use
//! of a heap:
//!
//! - [`PrivateKeyInfo`]: algorithm identifier and data representing a private key.
//! - [`SubjectPublicKeyInfo`]: algorithm identifier and data representing a public key.
//!
//! When the `alloc` feature is enabled, the following additional types are
//! available which provide more convenient decoding/encoding support:
//!
//! - [`PrivateKeyDocument`]: heap-backed storage for serialized [`PrivateKeyInfo`].
//! - [`PublicKeyDocument`]: heap-backed storage for serialized [`SubjectPublicKeyInfo`].
//!
//! When the `pem` feature is enabled, it also supports decoding/encoding
//! documents from "PEM encoding" format as defined in RFC 7468.
//!
//! # Supported Algorithms
//!
//! This crate has been tested against keys generated by OpenSSL for the
//! following algorithms:
//!
//! - ECC (`id-ecPublicKey`)
//! - Ed25519 (`Ed25519`)
//! - RSA (`rsaEncryption`)
//!
//! It may work with other algorithms which use an optional OID for
//! [`AlgorithmIdentifier`] parameters.
//!
//! Encrypted private keys are presently unsupported.
//!
//! # Minimum Supported Rust Version
//!
//! This crate requires **Rust 1.46** at a minimum.
//!
//! [RFC 5208]: https://tools.ietf.org/html/rfc5208

#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(
    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
    html_root_url = "https://docs.rs/pkcs8/0.4.1"
)]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms)]

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

mod algorithm;
mod error;
mod private_key_info;
mod spki;
mod traits;

#[cfg(feature = "alloc")]
mod document;

#[cfg(feature = "pem")]
mod pem;

pub use crate::{
    algorithm::{AlgorithmIdentifier, AlgorithmParameters},
    error::{Error, Result},
    private_key_info::PrivateKeyInfo,
    spki::SubjectPublicKeyInfo,
    traits::{FromPrivateKey, FromPublicKey},
};
pub use der::{self, ObjectIdentifier};

#[cfg(feature = "alloc")]
pub use crate::{
    document::{PrivateKeyDocument, PublicKeyDocument},
    traits::{ToPrivateKey, ToPublicKey},
};