pub struct Certificate { /* private fields */ }Expand description
Wraps SecCertificateRef.
Implementations§
Source§impl Certificate
impl Certificate
Sourcepub fn from_der(der: &[u8]) -> Result<Self>
pub fn from_der(der: &[u8]) -> Result<Self>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
More examples
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>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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>>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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}More examples
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let private_key = PrivateKey::from_data(
7 &std::fs::read("tests/fixtures/test-key-rsa.pkcs1.der")?,
8 KeyType::Rsa,
9 2048,
10 )?;
11 let public_key = private_key.public_key()?;
12
13 let ciphertext = public_key.encrypt(
14 EncryptionAlgorithm::RsaEncryptionOaepSha256,
15 b"security-rs example",
16 )?;
17 let plaintext =
18 private_key.decrypt(EncryptionAlgorithm::RsaEncryptionOaepSha256, &ciphertext)?;
19 assert_eq!(plaintext, b"security-rs example");
20
21 let signature = private_key.sign(
22 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
23 b"security-rs example",
24 )?;
25 let certificate = Certificate::from_pem(&std::fs::read("tests/fixtures/test-cert.pem")?)?;
26 assert!(certificate.public_key()?.verify_signature(
27 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
28 b"security-rs example",
29 &signature,
30 )?);
31
32 println!(
33 "key_type_id={} block_size={} exported_private={} exported_public={}",
34 PrivateKey::type_id(),
35 public_key.block_size(),
36 private_key.external_representation()?.len(),
37 public_key.external_representation()?.len(),
38 );
39
40 Ok(())
41}Sourcepub fn subject_summary(&self) -> Result<Option<String>>
pub fn subject_summary(&self) -> Result<Option<String>>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let identity =
8 Identity::import_pkcs12_first(&support::fixture("test-identity.p12"), "password")?;
9 let certificate = identity.certificate()?;
10 println!(
11 "label={:?} chain_count={} subject={:?}",
12 identity.label()?,
13 identity.chain_count(),
14 certificate.subject_summary()?
15 );
16 Ok(())
17}More examples
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 common_name(&self) -> Result<Option<String>>
pub fn common_name(&self) -> Result<Option<String>>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn email_addresses(&self) -> Result<Vec<String>>
pub fn email_addresses(&self) -> Result<Vec<String>>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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 normalized_subject_sequence(&self) -> Result<Vec<u8>>
pub fn normalized_subject_sequence(&self) -> Result<Vec<u8>>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn normalized_issuer_sequence(&self) -> Result<Vec<u8>>
pub fn normalized_issuer_sequence(&self) -> Result<Vec<u8>>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn serial_number(&self) -> Result<Vec<u8>>
pub fn serial_number(&self) -> Result<Vec<u8>>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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 not_valid_before(&self) -> Result<Option<SystemTime>>
pub fn not_valid_before(&self) -> Result<Option<SystemTime>>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn not_valid_after(&self) -> Result<Option<SystemTime>>
pub fn not_valid_after(&self) -> Result<Option<SystemTime>>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn public_key(&self) -> Result<PublicKey>
pub fn public_key(&self) -> Result<PublicKey>
Wraps the corresponding SecCertificateRef operation.
Examples found in repository?
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}More examples
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let private_key = PrivateKey::from_data(
7 &std::fs::read("tests/fixtures/test-key-rsa.pkcs1.der")?,
8 KeyType::Rsa,
9 2048,
10 )?;
11 let public_key = private_key.public_key()?;
12
13 let ciphertext = public_key.encrypt(
14 EncryptionAlgorithm::RsaEncryptionOaepSha256,
15 b"security-rs example",
16 )?;
17 let plaintext =
18 private_key.decrypt(EncryptionAlgorithm::RsaEncryptionOaepSha256, &ciphertext)?;
19 assert_eq!(plaintext, b"security-rs example");
20
21 let signature = private_key.sign(
22 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
23 b"security-rs example",
24 )?;
25 let certificate = Certificate::from_pem(&std::fs::read("tests/fixtures/test-cert.pem")?)?;
26 assert!(certificate.public_key()?.verify_signature(
27 SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
28 b"security-rs example",
29 &signature,
30 )?);
31
32 println!(
33 "key_type_id={} block_size={} exported_private={} exported_public={}",
34 PrivateKey::type_id(),
35 public_key.block_size(),
36 private_key.external_representation()?.len(),
37 public_key.external_representation()?.len(),
38 );
39
40 Ok(())
41}Sourcepub fn add_to_keychain(&self) -> Result<()>
pub fn add_to_keychain(&self) -> Result<()>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn values(&self, keys: &[&str]) -> Result<Value>
pub fn values(&self, keys: &[&str]) -> Result<Value>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn long_description(&self) -> Result<String>
pub fn long_description(&self) -> Result<String>
Wraps the corresponding SecCertificateRef operation.
Sourcepub fn short_description(&self) -> Result<String>
pub fn short_description(&self) -> Result<String>
Wraps the corresponding SecCertificateRef operation.