Commit 2fd201d9 authored by Steven Fackler's avatar Steven Fackler
Browse files

De-enumify Nid

parent ae72cbd2
Loading
Loading
Loading
Loading
+949 −3

File changed.

Preview size limit exceeded, changes collapsed.

+3820 −196

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -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,
        }
+3 −3
Original line number Diff line number Diff line
@@ -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;
            }
+10 −10
Original line number Diff line number Diff line
@@ -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, "test@example.com");

    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"),
    };