Skip to main content

spki/
lib.rs

1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![doc = include_str!("../README.md")]
4#![doc(
5    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
6    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
7)]
8#![forbid(unsafe_code)]
9
10//! # Usage
11//! The following example demonstrates how to use an OID as the `parameters`
12//! of an [`AlgorithmIdentifier`].
13//!
14//! Borrow the [`ObjectIdentifier`] first then use [`der::AnyRef::from`] or `.into()`:
15//!
16//! ```
17//! use spki::{AlgorithmIdentifier, ObjectIdentifier};
18//!
19//! let alg_oid = "1.2.840.10045.2.1".parse::<ObjectIdentifier>().unwrap();
20//! let params_oid = "1.2.840.10045.3.1.7".parse::<ObjectIdentifier>().unwrap();
21//!
22//! let alg_id = AlgorithmIdentifier {
23//!     oid: alg_oid,
24//!     parameters: Some(params_oid)
25//! };
26//! ```
27
28#[cfg(feature = "alloc")]
29#[allow(unused_extern_crates)]
30extern crate alloc;
31#[cfg(feature = "std")]
32extern crate std;
33
34mod algorithm;
35mod error;
36mod spki;
37mod traits;
38
39#[cfg(feature = "digest")]
40mod digest;
41
42pub use crate::{
43    algorithm::{
44        AlgorithmIdentifier, AlgorithmIdentifierRef, AlgorithmIdentifierWithOid,
45        AsAlgorithmIdentifierRef,
46    },
47    error::{Error, Result},
48    spki::{SubjectPublicKeyInfo, SubjectPublicKeyInfoRef},
49    traits::{AssociatedAlgorithmIdentifier, DecodePublicKey, SignatureAlgorithmIdentifier},
50};
51pub use der::{self, asn1::ObjectIdentifier};
52
53#[cfg(feature = "alloc")]
54pub use {
55    crate::{
56        algorithm::AlgorithmIdentifierOwned,
57        spki::SubjectPublicKeyInfoOwned,
58        traits::{
59            DynAssociatedAlgorithmIdentifier, DynSignatureAlgorithmIdentifier, EncodePublicKey,
60            SignatureBitStringEncoding,
61        },
62    },
63    der::Document,
64};
65
66#[cfg(feature = "digest")]
67pub use crate::digest::DigestWriter;
68
69/// Size of a SHA-256 SPKI fingerprint in bytes.
70#[cfg(feature = "fingerprint")]
71pub(crate) const SIZE: usize = 32;
72
73/// Raw bytes of a SPKI fingerprint i.e. SHA-256 digest of
74/// `SubjectPublicKeyInfo`'s DER encoding.
75///
76/// See [RFC7469 § 2.1.1] for more information.
77///
78/// [RFC7469 § 2.1.1]: https://datatracker.ietf.org/doc/html/rfc7469#section-2.1.1
79#[cfg(feature = "fingerprint")]
80pub type FingerprintBytes = [u8; SIZE];