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::{AlgorithmIdentifier, AlgorithmIdentifierRef, AlgorithmIdentifierWithOid},
44    error::{Error, Result},
45    spki::{SubjectPublicKeyInfo, SubjectPublicKeyInfoRef},
46    traits::{AssociatedAlgorithmIdentifier, DecodePublicKey, SignatureAlgorithmIdentifier},
47};
48pub use der::{self, asn1::ObjectIdentifier};
49
50#[cfg(feature = "alloc")]
51pub use {
52    crate::{
53        algorithm::AlgorithmIdentifierOwned,
54        spki::SubjectPublicKeyInfoOwned,
55        traits::{
56            DynAssociatedAlgorithmIdentifier, DynSignatureAlgorithmIdentifier, EncodePublicKey,
57            SignatureBitStringEncoding,
58        },
59    },
60    der::Document,
61};
62
63#[cfg(feature = "digest")]
64pub use crate::digest::DigestWriter;
65
66/// Size of a SHA-256 SPKI fingerprint in bytes.
67#[cfg(feature = "fingerprint")]
68pub(crate) const SIZE: usize = 32;
69
70/// Raw bytes of a SPKI fingerprint i.e. SHA-256 digest of
71/// `SubjectPublicKeyInfo`'s DER encoding.
72///
73/// See [RFC7469 § 2.1.1] for more information.
74///
75/// [RFC7469 § 2.1.1]: https://datatracker.ietf.org/doc/html/rfc7469#section-2.1.1
76#[cfg(feature = "fingerprint")]
77pub type FingerprintBytes = [u8; SIZE];