diff options
| author | Steven Fackler <[email protected]> | 2016-10-22 15:58:06 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-22 15:58:06 -0700 |
| commit | 787cad3c8225b0c09135305477d5a962fc64d9bb (patch) | |
| tree | acf80953c3b5fbb2323976a7f723ad97c616268d /openssl/src/x509 | |
| parent | Camel case Rsa (diff) | |
| download | rust-openssl-787cad3c8225b0c09135305477d5a962fc64d9bb.tar.xz rust-openssl-787cad3c8225b0c09135305477d5a962fc64d9bb.zip | |
Use constants rather than constructors for Nid
Diffstat (limited to 'openssl/src/x509')
| -rw-r--r-- | openssl/src/x509/extension.rs | 10 | ||||
| -rw-r--r-- | openssl/src/x509/tests.rs | 22 |
2 files changed, 16 insertions, 16 deletions
diff --git a/openssl/src/x509/extension.rs b/openssl/src/x509/extension.rs index fc6b3c3b..7ac66383 100644 --- a/openssl/src/x509/extension.rs +++ b/openssl/src/x509/extension.rs @@ -1,6 +1,6 @@ use std::fmt; -use nid::Nid; +use nid::{self, Nid}; /// Type-only version of the `Extension` enum. /// @@ -71,10 +71,10 @@ impl Extension { impl ExtensionType { pub fn get_nid(&self) -> Option<Nid> { match self { - &ExtensionType::KeyUsage => Some(Nid::key_usage()), - &ExtensionType::ExtKeyUsage => Some(Nid::ext_key_usage()), - &ExtensionType::SubjectAltName => Some(Nid::subject_alt_name()), - &ExtensionType::IssuerAltName => Some(Nid::issuer_alt_name()), + &ExtensionType::KeyUsage => Some(nid::KEY_USAGE), + &ExtensionType::ExtKeyUsage => Some(nid::EXT_KEY_USAGE), + &ExtensionType::SubjectAltName => Some(nid::SUBJECT_ALT_NAME), + &ExtensionType::IssuerAltName => Some(nid::ISSUER_ALT_NAME), &ExtensionType::OtherNid(nid) => Some(nid), &ExtensionType::OtherStr(_) => None, } diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index c0c7ce87..185c4910 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -8,7 +8,7 @@ use x509::extension::Extension::{KeyUsage, ExtKeyUsage, SubjectAltName, OtherNid use x509::extension::AltNameOption as SAN; use x509::extension::KeyUsageOption::{DigitalSignature, KeyEncipherment}; use x509::extension::ExtKeyUsageOption::{self, ClientAuth, ServerAuth}; -use nid::Nid; +use nid; fn get_generator() -> X509Generator { X509Generator::new() @@ -20,7 +20,7 @@ fn get_generator() -> X509Generator { ServerAuth, ExtKeyUsageOption::Other("2.999.1".to_owned())])) .add_extension(SubjectAltName(vec![(SAN::DNS, "example.com".to_owned())])) - .add_extension(OtherNid(Nid::basic_constraints(), "critical,CA:TRUE".to_owned())) + .add_extension(OtherNid(nid::BASIC_CONSTRAINTS, "critical,CA:TRUE".to_owned())) .add_extension(OtherStr("2.999.2".to_owned(), "ASN1:UTF8:example value".to_owned())) } @@ -48,8 +48,8 @@ fn test_cert_gen() { fn test_cert_gen_extension_ordering() { let pkey = pkey(); get_generator() - .add_extension(OtherNid(Nid::subject_key_identifier(), "hash".to_owned())) - .add_extension(OtherNid(Nid::authority_key_identifier(), "keyid:always".to_owned())) + .add_extension(OtherNid(nid::SUBJECT_KEY_IDENTIFIER, "hash".to_owned())) + .add_extension(OtherNid(nid::AUTHORITY_KEY_IDENTIFIER, "keyid:always".to_owned())) .sign(&pkey) .expect("Failed to generate cert with order-dependent extensions"); } @@ -60,9 +60,9 @@ fn test_cert_gen_extension_ordering() { fn test_cert_gen_extension_bad_ordering() { let pkey = pkey(); let result = get_generator() - .add_extension(OtherNid(Nid::authority_key_identifier(), + .add_extension(OtherNid(nid::AUTHORITY_KEY_IDENTIFIER, "keyid:always".to_owned())) - .add_extension(OtherNid(Nid::subject_key_identifier(), "hash".to_owned())) + .add_extension(OtherNid(nid::SUBJECT_KEY_IDENTIFIER, "hash".to_owned())) .sign(&pkey); assert!(result.is_err()); @@ -116,7 +116,7 @@ fn test_subject_read_cn() { let cert = include_bytes!("../../test/cert.pem"); let cert = X509::from_pem(cert).ok().expect("Failed to load PEM"); let subject = cert.subject_name(); - let cn = match subject.text_by_nid(Nid::commonName()) { + let cn = match subject.text_by_nid(nid::COMMONNAME) { Some(x) => x, None => panic!("Failed to read CN from cert"), }; @@ -130,19 +130,19 @@ fn test_nid_values() { let cert = X509::from_pem(cert).ok().expect("Failed to load PEM"); let subject = cert.subject_name(); - let cn = match subject.text_by_nid(Nid::commonName()) { + let cn = match subject.text_by_nid(nid::COMMONNAME) { Some(x) => x, None => panic!("Failed to read CN from cert"), }; assert_eq!(&cn as &str, "example.com"); - let email = match subject.text_by_nid(Nid::pkcs9_emailAddress()) { + let email = match subject.text_by_nid(nid::PKCS9_EMAILADDRESS) { Some(x) => x, None => panic!("Failed to read subject email address from cert"), }; assert_eq!(&email as &str, "[email protected]"); - let friendly = match subject.text_by_nid(Nid::friendlyName()) { + let friendly = match subject.text_by_nid(nid::FRIENDLYNAME) { Some(x) => x, None => panic!("Failed to read subject friendly name from cert"), }; @@ -155,7 +155,7 @@ fn test_nid_uid_value() { let cert = X509::from_pem(cert).ok().expect("Failed to load PEM"); let subject = cert.subject_name(); - let cn = match subject.text_by_nid(Nid::userId()) { + let cn = match subject.text_by_nid(nid::USERID) { Some(x) => x, None => panic!("Failed to read UID from cert"), }; |