pub struct CertificateBuilder<P> { /* private fields */ }Expand description
X509 Certificate builder
use der::Decode;
use x509_cert::spki::SubjectPublicKeyInfo;
use x509_cert::builder::{CertificateBuilder, Builder, profile};
use x509_cert::name::Name;
use x509_cert::serial_number::SerialNumber;
use x509_cert::time::Validity;
use std::str::FromStr;
let serial_number = SerialNumber::from(42u32);
let validity = Validity::from_now(Duration::new(5, 0)).unwrap();
let subject = Name::from_str("CN=World domination corporation,O=World domination Inc,C=US").unwrap();
let profile = profile::cabf::Root::new(false,subject).expect("Create root profile");
let pub_key = SubjectPublicKeyInfo::try_from(RSA_2048_DER).expect("get rsa pub key");
let mut signer = rsa_signer();
let mut builder = CertificateBuilder::new(
profile,
serial_number,
validity,
pub_key,
)
.expect("Create certificate builder");
let cert = builder.build(&signer).expect("Create certificate");Implementations§
Source§impl<P> CertificateBuilder<P>where
P: BuilderProfile,
impl<P> CertificateBuilder<P>where
P: BuilderProfile,
Sourcepub fn new(
profile: P,
serial_number: SerialNumber,
validity: Validity,
subject_public_key_info: SubjectPublicKeyInfo<Any, BitString>,
) -> Result<CertificateBuilder<P>, Error>
pub fn new( profile: P, serial_number: SerialNumber, validity: Validity, subject_public_key_info: SubjectPublicKeyInfo<Any, BitString>, ) -> Result<CertificateBuilder<P>, Error>
Creates a new certificate builder
Sourcepub fn add_extension<E>(
&mut self,
extension: E,
) -> Result<(), <E as ToExtension>::Error>where
E: ToExtension,
pub fn add_extension<E>(
&mut self,
extension: E,
) -> Result<(), <E as ToExtension>::Error>where
E: ToExtension,
Add an extension to this certificate
Extensions need to implement ToExtension, examples may be found in
in ToExtension documentation or
the implementors.
Trait Implementations§
Source§impl<P> Builder for CertificateBuilder<P>where
P: BuilderProfile,
impl<P> Builder for CertificateBuilder<P>where
P: BuilderProfile,
Source§type Output = CertificateInner
type Output = CertificateInner
Type built by this builder
Source§fn finalize<S>(&mut self, cert_signer: &S) -> Result<Vec<u8>, Error>
fn finalize<S>(&mut self, cert_signer: &S) -> Result<Vec<u8>, Error>
Finalize and return a serialization of the object for signature.
Source§fn assemble<S>(
self,
signature: BitString,
_signer: &S,
) -> Result<<CertificateBuilder<P> as Builder>::Output, Error>
fn assemble<S>( self, signature: BitString, _signer: &S, ) -> Result<<CertificateBuilder<P> as Builder>::Output, Error>
Assemble the final object from signature.
Source§fn build<S, Signature>(self, signer: &S) -> Result<Self::Output, Error>where
S: Signer<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
fn build<S, Signature>(self, signer: &S) -> Result<Self::Output, Error>where
S: Signer<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
Run the object through the signer and build it. Read more
Source§fn build_with_rng<S, Signature, R>(
self,
signer: &S,
rng: &mut R,
) -> Result<Self::Output, Error>where
S: RandomizedSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
R: CryptoRng + ?Sized,
fn build_with_rng<S, Signature, R>(
self,
signer: &S,
rng: &mut R,
) -> Result<Self::Output, Error>where
S: RandomizedSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
R: CryptoRng + ?Sized,
Run the object through the signer and build it. Read more
Auto Trait Implementations§
impl<P> Freeze for CertificateBuilder<P>where
P: Freeze,
impl<P> RefUnwindSafe for CertificateBuilder<P>where
P: RefUnwindSafe,
impl<P> Send for CertificateBuilder<P>where
P: Send,
impl<P> Sync for CertificateBuilder<P>where
P: Sync,
impl<P> Unpin for CertificateBuilder<P>where
P: Unpin,
impl<P> UnsafeUnpin for CertificateBuilder<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for CertificateBuilder<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsyncBuilder for Twhere
T: Builder,
impl<T> AsyncBuilder for Twhere
T: Builder,
Source§fn assemble<S>(
self,
signature: BitString,
signer: &S,
) -> Result<<T as AsyncBuilder>::Output, Error>
fn assemble<S>( self, signature: BitString, signer: &S, ) -> Result<<T as AsyncBuilder>::Output, Error>
Assemble the final object from signature.
Source§fn finalize<S>(&mut self, signer: &S) -> Result<Vec<u8>, Error>
fn finalize<S>(&mut self, signer: &S) -> Result<Vec<u8>, Error>
Finalize and return a serialization of the object for signature.
Source§async fn build_async<S, Signature>(
self,
signer: &S,
) -> Result<Self::Output, Error>where
S: AsyncSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
async fn build_async<S, Signature>(
self,
signer: &S,
) -> Result<Self::Output, Error>where
S: AsyncSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
Run the object through the signer and build it. Read more
Source§async fn build_with_rng_async<S, Signature, R>(
self,
signer: &S,
rng: &mut R,
) -> Result<Self::Output, Error>where
S: AsyncRandomizedSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
R: CryptoRng + ?Sized,
async fn build_with_rng_async<S, Signature, R>(
self,
signer: &S,
rng: &mut R,
) -> Result<Self::Output, Error>where
S: AsyncRandomizedSigner<Signature> + Keypair + DynSignatureAlgorithmIdentifier,
<S as Keypair>::VerifyingKey: EncodePublicKey,
Signature: SignatureBitStringEncoding,
R: CryptoRng + ?Sized,
Run the object through the signer and build it. Read more
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more