aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2017-12-25 19:19:47 -0700
committerSteven Fackler <[email protected]>2017-12-25 19:19:47 -0700
commit2aaba8bd7ac9953edc0d86f9575862412ac26d98 (patch)
tree2573e52ba929d336a4324ef5d3a5e5a79fac944c /openssl/src/x509
parentMerge pull request #795 from sfackler/host-overhaul (diff)
downloadrust-openssl-2aaba8bd7ac9953edc0d86f9575862412ac26d98.tar.xz
rust-openssl-2aaba8bd7ac9953edc0d86f9575862412ac26d98.zip
Make Nid values associated constants
Diffstat (limited to 'openssl/src/x509')
-rw-r--r--openssl/src/x509/extension.rs52
-rw-r--r--openssl/src/x509/mod.rs42
2 files changed, 39 insertions, 55 deletions
diff --git a/openssl/src/x509/extension.rs b/openssl/src/x509/extension.rs
index 83a82660..cbc6b806 100644
--- a/openssl/src/x509/extension.rs
+++ b/openssl/src/x509/extension.rs
@@ -1,8 +1,8 @@
use std::fmt::{self, Write};
use error::ErrorStack;
-use nid::{self, Nid};
-use x509::{X509v3Context, X509Extension};
+use nid::Nid;
+use x509::{X509Extension, X509v3Context};
/// Type-only version of the `Extension` enum.
///
@@ -77,10 +77,10 @@ impl ExtensionType {
#[deprecated(since = "0.9.7", note = "use X509Builder and X509ReqBuilder instead")]
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,
}
@@ -112,22 +112,18 @@ impl ToString for Extension {
match self {
&Extension::KeyUsage(ref purposes) => join(purposes.iter(), ","),
&Extension::ExtKeyUsage(ref purposes) => join(purposes.iter(), ","),
- &Extension::SubjectAltName(ref names) => {
- join(
- names.iter().map(|&(ref opt, ref val)| {
- opt.to_string() + ":" + &val
- }),
- ",",
- )
- }
- &Extension::IssuerAltName(ref names) => {
- join(
- names.iter().map(|&(ref opt, ref val)| {
- opt.to_string() + ":" + &val
- }),
- ",",
- )
- }
+ &Extension::SubjectAltName(ref names) => join(
+ names
+ .iter()
+ .map(|&(ref opt, ref val)| opt.to_string() + ":" + &val),
+ ",",
+ ),
+ &Extension::IssuerAltName(ref names) => join(
+ names
+ .iter()
+ .map(|&(ref opt, ref val)| opt.to_string() + ":" + &val),
+ ",",
+ ),
&Extension::OtherNid(_, ref value) => value.clone(),
&Extension::OtherStr(_, ref value) => value.clone(),
}
@@ -282,7 +278,7 @@ impl BasicConstraints {
if let Some(pathlen) = self.pathlen {
write!(value, ",pathlen:{}", pathlen).unwrap();
}
- X509Extension::new_nid(None, None, nid::BASIC_CONSTRAINTS, &value)
+ X509Extension::new_nid(None, None, Nid::BASIC_CONSTRAINTS, &value)
}
}
@@ -398,7 +394,7 @@ impl KeyUsage {
append(&mut value, &mut first, self.crl_sign, "cRLSign");
append(&mut value, &mut first, self.encipher_only, "encipherOnly");
append(&mut value, &mut first, self.decipher_only, "decipherOnly");
- X509Extension::new_nid(None, None, nid::KEY_USAGE, &value)
+ X509Extension::new_nid(None, None, Nid::KEY_USAGE, &value)
}
}
@@ -520,7 +516,7 @@ impl ExtendedKeyUsage {
for other in &self.other {
append(&mut value, &mut first, true, other);
}
- X509Extension::new_nid(None, None, nid::EXT_KEY_USAGE, &value)
+ X509Extension::new_nid(None, None, Nid::EXT_KEY_USAGE, &value)
}
}
@@ -543,7 +539,7 @@ impl SubjectKeyIdentifier {
let mut first = true;
append(&mut value, &mut first, self.critical, "critical");
append(&mut value, &mut first, true, "hash");
- X509Extension::new_nid(None, Some(ctx), nid::SUBJECT_KEY_IDENTIFIER, &value)
+ X509Extension::new_nid(None, Some(ctx), Nid::SUBJECT_KEY_IDENTIFIER, &value)
}
}
@@ -591,7 +587,7 @@ impl AuthorityKeyIdentifier {
Some(false) => append(&mut value, &mut first, true, "issuer"),
None => {}
}
- X509Extension::new_nid(None, Some(ctx), nid::AUTHORITY_KEY_IDENTIFIER, &value)
+ X509Extension::new_nid(None, Some(ctx), Nid::AUTHORITY_KEY_IDENTIFIER, &value)
}
}
@@ -655,7 +651,7 @@ impl SubjectAlternativeName {
for name in &self.names {
append(&mut value, &mut first, true, name);
}
- X509Extension::new_nid(None, Some(ctx), nid::SUBJECT_ALT_NAME, &value)
+ X509Extension::new_nid(None, Some(ctx), Nid::SUBJECT_ALT_NAME, &value)
}
}
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index db9d6df5..faf93780 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -13,30 +13,30 @@ use std::ptr;
use std::slice;
use std::str;
-use {cvt, cvt_p, cvt_n};
-use asn1::{Asn1StringRef, Asn1Time, Asn1TimeRef, Asn1BitStringRef, Asn1IntegerRef, Asn1ObjectRef};
+use {cvt, cvt_n, cvt_p};
+use asn1::{Asn1BitStringRef, Asn1IntegerRef, Asn1ObjectRef, Asn1StringRef, Asn1Time, Asn1TimeRef};
use bio::MemBioSlice;
use bn::{BigNum, MSB_MAYBE_ZERO};
use conf::ConfRef;
use error::ErrorStack;
use hash::MessageDigest;
-use nid::{self, Nid};
+use nid::Nid;
use pkey::{PKey, PKeyRef};
use stack::{Stack, StackRef, Stackable};
use string::OpensslString;
use ssl::SslRef;
#[cfg(ossl10x)]
-use ffi::{X509_set_notBefore, X509_set_notAfter, ASN1_STRING_data, X509_STORE_CTX_get_chain};
+use ffi::{ASN1_STRING_data, X509_STORE_CTX_get_chain, X509_set_notAfter, X509_set_notBefore};
#[cfg(ossl110)]
-use ffi::{X509_set1_notBefore as X509_set_notBefore, X509_set1_notAfter as X509_set_notAfter,
- ASN1_STRING_get0_data as ASN1_STRING_data,
- X509_STORE_CTX_get0_chain as X509_STORE_CTX_get_chain};
+use ffi::{ASN1_STRING_get0_data as ASN1_STRING_data,
+ X509_STORE_CTX_get0_chain as X509_STORE_CTX_get_chain,
+ X509_set1_notAfter as X509_set_notAfter, X509_set1_notBefore as X509_set_notBefore};
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub mod verify;
-use x509::extension::{ExtensionType, Extension};
+use x509::extension::{Extension, ExtensionType};
pub mod extension;
pub mod store;
@@ -237,7 +237,7 @@ impl X509Generator {
let mut name = X509Name::builder()?;
if self.names.is_empty() {
- name.append_entry_by_nid(nid::COMMONNAME, "rust-openssl")?;
+ name.append_entry_by_nid(Nid::COMMONNAME, "rust-openssl")?;
} else {
for &(ref key, ref value) in &self.names {
name.append_entry_by_text(key, value)?;
@@ -252,12 +252,7 @@ impl X509Generator {
let extension = match exttype.get_nid() {
Some(nid) => {
let ctx = builder.x509v3_context(None, None);
- X509Extension::new_nid(
- None,
- Some(&ctx),
- nid,
- &ext.to_string(),
- )?
+ X509Extension::new_nid(None, Some(&ctx), nid, &ext.to_string())?
}
None => {
let ctx = builder.x509v3_context(None, None);
@@ -294,15 +289,11 @@ impl X509Generator {
let exts = compat::X509_get0_extensions(cert.as_ptr());
if exts != ptr::null_mut() {
- cvt(
- ffi::X509_REQ_add_extensions(req.as_ptr(), exts as *mut _),
- )?;
+ cvt(ffi::X509_REQ_add_extensions(req.as_ptr(), exts as *mut _))?;
}
let hash_fn = self.hash_type.as_ptr();
- cvt(
- ffi::X509_REQ_sign(req.as_ptr(), p_key.as_ptr(), hash_fn),
- )?;
+ cvt(ffi::X509_REQ_sign(req.as_ptr(), p_key.as_ptr(), hash_fn))?;
Ok(req)
}
@@ -428,9 +419,7 @@ impl X509Builder {
/// Adds an X509 extension value to the certificate.
pub fn append_extension(&mut self, extension: X509Extension) -> Result<(), ErrorStack> {
unsafe {
- cvt(
- ffi::X509_add_ext(self.0.as_ptr(), extension.as_ptr(), -1),
- )?;
+ cvt(ffi::X509_add_ext(self.0.as_ptr(), extension.as_ptr(), -1))?;
mem::forget(extension);
Ok(())
}
@@ -595,8 +584,8 @@ impl X509 {
ffi::PEM_read_bio_X509(bio.as_ptr(), ptr::null_mut(), None, ptr::null_mut());
if r.is_null() {
let err = ffi::ERR_peek_last_error();
- if ffi::ERR_GET_LIB(err) == ffi::ERR_LIB_PEM &&
- ffi::ERR_GET_REASON(err) == ffi::PEM_R_NO_START_LINE
+ if ffi::ERR_GET_LIB(err) == ffi::ERR_LIB_PEM
+ && ffi::ERR_GET_REASON(err) == ffi::PEM_R_NO_START_LINE
{
ffi::ERR_clear_error();
break;
@@ -837,7 +826,6 @@ impl X509ReqBuilder {
ffi::init();
cvt_p(ffi::X509_REQ_new()).map(|p| X509ReqBuilder(X509Req(p)))
}
-
}
pub fn set_version(&mut self, version: i32) -> Result<(), ErrorStack> {