pub struct CertificateKey(/* private fields */);Expand description
A TLS certificate key: a key of one of the profile’s TLS key algorithms (Resolved::keys),
for a certificate request (csr::generate_csr) and this side’s certificate
(Resolved::certified_key). It is held once, as the module’s parsed key (decision 0012), and
is not Clone; its Debug prints the algorithm only. It has no sign; it signs through the
TLS key provider with the policy’s TLS schemes, and that signer signs whatever bytes it is
given (decision 0016, residual 2). Its PKCS#8 export is the private key, which imports as a
signature::KeyPair only under an Admitted whose signatures admit the algorithm; what else
takes it is decision 0016, residuals 2 and 4.
use crypto_profile_awslc3::{Options, Profile, SignatureAlgorithm, csr, resolve, tls};
let r = resolve(Profile::Fips1403, Options::default())?;
let key = tls::CertificateKey::generate(&r, SignatureAlgorithm::EcdsaP384Sha384)?;
let request = csr::generate_csr(&key, &csr::CsrParams::default())?;
assert!(request.starts_with("-----BEGIN CERTIFICATE REQUEST-----"));
let der = key.to_pkcs8_der()?;
let again = tls::CertificateKey::from_pkcs8_der(&r, SignatureAlgorithm::EcdsaP384Sha384, &der)?;
assert_eq!(again.public_key(), key.public_key());Implementations§
Source§impl CertificateKey
impl CertificateKey
Sourcepub fn generate(
r: &Resolved,
a: SignatureAlgorithm,
) -> Result<CertificateKey, CryptoError>
pub fn generate( r: &Resolved, a: SignatureAlgorithm, ) -> Result<CertificateKey, CryptoError>
A new key of algorithm a. Refuses, in this order, an algorithm not in r.keys
(CryptoError::KeyNotInProfile), then one the module line lacks
(CryptoError::Unavailable), then a failed generation (CryptoError::KeyGeneration).
Sourcepub fn from_pkcs8_der(
r: &Resolved,
a: SignatureAlgorithm,
der: &[u8],
) -> Result<CertificateKey, CryptoError>
pub fn from_pkcs8_der( r: &Resolved, a: SignatureAlgorithm, der: &[u8], ) -> Result<CertificateKey, CryptoError>
Imports a DER RFC 5958 §2 OneAsymmetricKey of algorithm a. Refuses, in this order, an
algorithm not in r.keys (CryptoError::KeyNotInProfile), then one the module line lacks
(CryptoError::Unavailable), then any structure or key signature::KeyPair::from_pkcs8_der
refuses (CryptoError::SignaturePrivateKey).
Sourcepub fn algorithm(&self) -> SignatureAlgorithm
pub fn algorithm(&self) -> SignatureAlgorithm
The key’s algorithm.
Sourcepub fn public_key(&self) -> &[u8] ⓘ
pub fn public_key(&self) -> &[u8] ⓘ
The raw public key: the bytes of the SubjectPublicKeyInfo subjectPublicKey BIT STRING.
Sourcepub fn to_pkcs8_der(&self) -> Result<Zeroizing<Vec<u8>>, CryptoError>
pub fn to_pkcs8_der(&self) -> Result<Zeroizing<Vec<u8>>, CryptoError>
The key’s PKCS#8 encoding, made by the module on each call into a buffer the caller owns and
that is wiped on drop, as signature::KeyPair::to_pkcs8_der makes it.