Skip to main content

CertificateKey

Struct CertificateKey 

Source
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

Source

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).

Source

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).

Source

pub fn algorithm(&self) -> SignatureAlgorithm

The key’s algorithm.

Source

pub fn public_key(&self) -> &[u8] ⓘ

The raw public key: the bytes of the SubjectPublicKeyInfo subjectPublicKey BIT STRING.

Source

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.

Trait Implementations§

Source§

impl Debug for CertificateKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.