[−][src]Struct openssl::x509::X509Generator
Generator of private key/certificate pairs
Example
use std::fs; use std::fs::File; use std::io::prelude::*; use std::path::Path; use openssl::crypto::hash::Type; use openssl::x509::X509Generator; use openssl::x509::extension::{Extension, KeyUsageOption}; let gen = X509Generator::new() .set_bitlength(2048) .set_valid_period(365*2) .add_name("CN".to_owned(), "SuperMegaCorp Inc.".to_owned()) .set_sign_hash(Type::SHA256) .add_extension(Extension::KeyUsage(vec![KeyUsageOption::DigitalSignature])); let (cert, pkey) = gen.generate().unwrap(); let cert_path = "doc_cert.pem"; let mut file = File::create(cert_path).unwrap(); assert!(cert.write_pem(&mut file).is_ok()); let pkey_path = "doc_key.pem"; let mut file = File::create(pkey_path).unwrap(); assert!(pkey.write_pem(&mut file).is_ok());
Methods
impl X509Generator
[src]
impl X509Generator
pub fn new() -> X509Generator
[src]
pub fn new() -> X509Generator
Creates a new generator with the following defaults:
bit length: 1024
validity period: 365 days
CN: "rust-openssl"
hash: SHA1
pub fn set_bitlength(self, bits: u32) -> X509Generator
[src]
pub fn set_bitlength(self, bits: u32) -> X509Generator
Sets desired bit length
pub fn set_valid_period(self, days: u32) -> X509Generator
[src]
pub fn set_valid_period(self, days: u32) -> X509Generator
Sets certificate validity period in days since today
pub fn add_name(self, attr_type: String, attr_value: String) -> X509Generator
[src]
pub fn add_name(self, attr_type: String, attr_value: String) -> X509Generator
Add attribute to the name of the certificate
generator.add_name("CN".to_string(),"example.com".to_string());
pub fn add_names<I>(self, attrs: I) -> X509Generator where
I: IntoIterator<Item = (String, String)>,
[src]
pub fn add_names<I>(self, attrs: I) -> X509Generator where
I: IntoIterator<Item = (String, String)>,
Add multiple attributes to the name of the certificate
generator.add_names(vec![("CN".to_string(),"example.com".to_string())]);
pub fn add_extension(self, ext: Extension) -> X509Generator
[src]
pub fn add_extension(self, ext: Extension) -> X509Generator
Add an extension to a certificate
If the extension already exists, it will be replaced.
use openssl::x509::extension::Extension::*; use openssl::x509::extension::KeyUsageOption::*; generator.add_extension(KeyUsage(vec![DigitalSignature, KeyEncipherment]));
pub fn add_extensions<I>(self, exts: I) -> X509Generator where
I: IntoIterator<Item = Extension>,
[src]
pub fn add_extensions<I>(self, exts: I) -> X509Generator where
I: IntoIterator<Item = Extension>,
Add multiple extensions to a certificate
If any of the extensions already exist, they will be replaced.
use openssl::x509::extension::Extension::*; use openssl::x509::extension::KeyUsageOption::*; generator.add_extensions(vec![KeyUsage(vec![DigitalSignature, KeyEncipherment])]);
pub fn set_sign_hash(self, hash_type: Type) -> X509Generator
[src]
pub fn set_sign_hash(self, hash_type: Type) -> X509Generator
pub fn generate<'a>(&self) -> Result<(X509<'a>, PKey), SslError>
[src]
pub fn generate<'a>(&self) -> Result<(X509<'a>, PKey), SslError>
Generates a private key and a self-signed certificate and returns them
pub fn sign<'a>(&self, p_key: &PKey) -> Result<X509<'a>, SslError>
[src]
pub fn sign<'a>(&self, p_key: &PKey) -> Result<X509<'a>, SslError>
Sets the certificate public-key, then self-sign and return it Note: That the bit-length of the private key is used (set_bitlength is ignored)
pub fn request(&self, p_key: &PKey) -> Result<X509Req, SslError>
[src]
pub fn request(&self, p_key: &PKey) -> Result<X509Req, SslError>
Obtain a certificate signing request (CSR)
Auto Trait Implementations
impl Send for X509Generator
impl Send for X509Generator
impl Sync for X509Generator
impl Sync for X509Generator
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more