pub struct Certificate { /* private fields */ }Implementations§
Source§impl Certificate
impl Certificate
Sourcepub fn import_item(
data: &[u8],
file_name_or_extension: Option<&str>,
format: ExternalFormat,
item_type: ExternalItemType,
) -> Result<Self>
pub fn import_item( data: &[u8], file_name_or_extension: Option<&str>, format: ExternalFormat, item_type: ExternalItemType, ) -> Result<Self>
Examples found in repository?
examples/03_certificate_inspect.rs (lines 7-12)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let certificate = Certificate::import_item(
8 &support::fixture("test-cert.pem"),
9 Some(".pem"),
10 ExternalFormat::Unknown,
11 ExternalItemType::Certificate,
12 )?;
13 let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14 println!(
15 "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16 certificate.subject_summary()?,
17 certificate.email_addresses()?,
18 certificate.serial_number()?.len(),
19 exported_pem.len()
20 );
21 Ok(())
22}Sourcepub fn export_item(
&self,
format: ExternalFormat,
pem_armour: bool,
) -> Result<Vec<u8>>
pub fn export_item( &self, format: ExternalFormat, pem_armour: bool, ) -> Result<Vec<u8>>
Examples found in repository?
examples/03_certificate_inspect.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let certificate = Certificate::import_item(
8 &support::fixture("test-cert.pem"),
9 Some(".pem"),
10 ExternalFormat::Unknown,
11 ExternalItemType::Certificate,
12 )?;
13 let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14 println!(
15 "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16 certificate.subject_summary()?,
17 certificate.email_addresses()?,
18 certificate.serial_number()?.len(),
19 exported_pem.len()
20 );
21 Ok(())
22}Sourcepub fn from_pem(pem: &[u8]) -> Result<Self>
pub fn from_pem(pem: &[u8]) -> Result<Self>
Examples found in repository?
examples/14_key_import_sign_verify.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let raw_key = PrivateKey::from_data(
8 &support::fixture("test-key-rsa.pkcs1.der"),
9 KeyType::Rsa,
10 2048,
11 )?;
12 let signature = raw_key.sign(
13 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
14 b"security-rs",
15 )?;
16 let certificate = Certificate::from_pem(&support::fixture("test-cert.pem"))?;
17 let verified = certificate.public_key()?.verify_signature(
18 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
19 b"security-rs",
20 &signature,
21 )?;
22 println!("signature_len={} verified={verified}", signature.len());
23 Ok(())
24}Sourcepub fn subject_summary(&self) -> Result<Option<String>>
pub fn subject_summary(&self) -> Result<Option<String>>
Examples found in repository?
More examples
examples/03_certificate_inspect.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let certificate = Certificate::import_item(
8 &support::fixture("test-cert.pem"),
9 Some(".pem"),
10 ExternalFormat::Unknown,
11 ExternalItemType::Certificate,
12 )?;
13 let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14 println!(
15 "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16 certificate.subject_summary()?,
17 certificate.email_addresses()?,
18 certificate.serial_number()?.len(),
19 exported_pem.len()
20 );
21 Ok(())
22}pub fn common_name(&self) -> Result<Option<String>>
Sourcepub fn email_addresses(&self) -> Result<Vec<String>>
pub fn email_addresses(&self) -> Result<Vec<String>>
Examples found in repository?
examples/03_certificate_inspect.rs (line 17)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let certificate = Certificate::import_item(
8 &support::fixture("test-cert.pem"),
9 Some(".pem"),
10 ExternalFormat::Unknown,
11 ExternalItemType::Certificate,
12 )?;
13 let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14 println!(
15 "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16 certificate.subject_summary()?,
17 certificate.email_addresses()?,
18 certificate.serial_number()?.len(),
19 exported_pem.len()
20 );
21 Ok(())
22}pub fn normalized_subject_sequence(&self) -> Result<Vec<u8>>
pub fn normalized_issuer_sequence(&self) -> Result<Vec<u8>>
Sourcepub fn serial_number(&self) -> Result<Vec<u8>>
pub fn serial_number(&self) -> Result<Vec<u8>>
Examples found in repository?
examples/03_certificate_inspect.rs (line 18)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let certificate = Certificate::import_item(
8 &support::fixture("test-cert.pem"),
9 Some(".pem"),
10 ExternalFormat::Unknown,
11 ExternalItemType::Certificate,
12 )?;
13 let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14 println!(
15 "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16 certificate.subject_summary()?,
17 certificate.email_addresses()?,
18 certificate.serial_number()?.len(),
19 exported_pem.len()
20 );
21 Ok(())
22}pub fn not_valid_before(&self) -> Result<Option<SystemTime>>
pub fn not_valid_after(&self) -> Result<Option<SystemTime>>
pub fn der_data(&self) -> Result<Vec<u8>>
Sourcepub fn public_key(&self) -> Result<PublicKey>
pub fn public_key(&self) -> Result<PublicKey>
Examples found in repository?
examples/14_key_import_sign_verify.rs (line 17)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let raw_key = PrivateKey::from_data(
8 &support::fixture("test-key-rsa.pkcs1.der"),
9 KeyType::Rsa,
10 2048,
11 )?;
12 let signature = raw_key.sign(
13 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
14 b"security-rs",
15 )?;
16 let certificate = Certificate::from_pem(&support::fixture("test-cert.pem"))?;
17 let verified = certificate.public_key()?.verify_signature(
18 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
19 b"security-rs",
20 &signature,
21 )?;
22 println!("signature_len={} verified={verified}", signature.len());
23 Ok(())
24}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Certificate
impl RefUnwindSafe for Certificate
impl !Send for Certificate
impl !Sync for Certificate
impl Unpin for Certificate
impl UnsafeUnpin for Certificate
impl UnwindSafe for Certificate
Blanket Implementations§
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