diff options
| author | Steven Fackler <[email protected]> | 2016-10-22 10:08:21 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-22 10:08:32 -0700 |
| commit | 2fd201d9c3df7fd76c0194fc10fa09cf5f0eb841 (patch) | |
| tree | 098bdb83db69b302fab0037c7bf6217e4c01f330 /openssl/src/x509 | |
| parent | Fix hasher docs (diff) | |
| download | rust-openssl-2fd201d9c3df7fd76c0194fc10fa09cf5f0eb841.tar.xz rust-openssl-2fd201d9c3df7fd76c0194fc10fa09cf5f0eb841.zip | |
De-enumify Nid
Diffstat (limited to 'openssl/src/x509')
| -rw-r--r-- | openssl/src/x509/extension.rs | 8 | ||||
| -rw-r--r-- | openssl/src/x509/mod.rs | 6 | ||||
| -rw-r--r-- | openssl/src/x509/tests.rs | 20 |
3 files changed, 17 insertions, 17 deletions
diff --git a/openssl/src/x509/extension.rs b/openssl/src/x509/extension.rs index 99ef62c1..fc6b3c3b 100644 --- a/openssl/src/x509/extension.rs +++ b/openssl/src/x509/extension.rs @@ -71,10 +71,10 @@ impl Extension { impl ExtensionType { pub fn get_nid(&self) -> Option<Nid> { match self { - &ExtensionType::KeyUsage => Some(Nid::KeyUsage), - &ExtensionType::ExtKeyUsage => Some(Nid::ExtendedKeyUsage), - &ExtensionType::SubjectAltName => Some(Nid::SubjectAltName), - &ExtensionType::IssuerAltName => Some(Nid::IssuerAltName), + &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/mod.rs b/openssl/src/x509/mod.rs index dfd61cac..8653b44e 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -257,7 +257,7 @@ impl X509Generator { Some(nid) => { try!(cvt_p(ffi::X509V3_EXT_conf_nid(ptr::null_mut(), mem::transmute(&ctx), - nid as c_int, + nid.as_raw(), value.as_ptr() as *mut c_char))) } None => { @@ -414,7 +414,7 @@ impl X509Ref { pub fn subject_alt_names(&self) -> Option<GeneralNames> { unsafe { let stack = ffi::X509_get_ext_d2i(self.as_ptr(), - Nid::SubjectAltName as c_int, + ffi::NID_subject_alt_name, ptr::null_mut(), ptr::null_mut()); if stack.is_null() { @@ -553,7 +553,7 @@ impl X509NameRef { pub fn text_by_nid(&self, nid: Nid) -> Option<SslString> { unsafe { - let loc = ffi::X509_NAME_get_index_by_NID(self.as_ptr(), nid as c_int, -1); + let loc = ffi::X509_NAME_get_index_by_NID(self.as_ptr(), nid.as_raw(), -1); if loc == -1 { return None; } diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index a5eb04e7..2a5d51a2 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -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::BasicConstraints, "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::SubjectKeyIdentifier, "hash".to_owned())) - .add_extension(OtherNid(Nid::AuthorityKeyIdentifier, "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::AuthorityKeyIdentifier, + .add_extension(OtherNid(Nid::authority_key_identifier(), "keyid:always".to_owned())) - .add_extension(OtherNid(Nid::SubjectKeyIdentifier, "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::CN) { + 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::CN) { + 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::Email) { + 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"), }; |