Make Nid values associated constants
This commit is contained in:
parent
82d3ac948b
commit
2aaba8bd7a
1887
openssl/src/nid.rs
1887
openssl/src/nid.rs
File diff suppressed because it is too large
Load Diff
|
|
@ -11,7 +11,7 @@ use pkey::{PKey, PKeyRef};
|
|||
use error::ErrorStack;
|
||||
use x509::X509;
|
||||
use stack::Stack;
|
||||
use nid;
|
||||
use nid::Nid;
|
||||
|
||||
foreign_type_and_impl_send_sync! {
|
||||
type CType = ffi::PKCS12;
|
||||
|
|
@ -75,8 +75,8 @@ impl Pkcs12 {
|
|||
ffi::init();
|
||||
|
||||
Pkcs12Builder {
|
||||
nid_key: nid::UNDEF, //nid::PBE_WITHSHA1AND3_KEY_TRIPLEDES_CBC,
|
||||
nid_cert: nid::UNDEF, //nid::PBE_WITHSHA1AND40BITRC2_CBC,
|
||||
nid_key: Nid::UNDEF, //nid::PBE_WITHSHA1AND3_KEY_TRIPLEDES_CBC,
|
||||
nid_cert: Nid::UNDEF, //nid::PBE_WITHSHA1AND40BITRC2_CBC,
|
||||
iter: ffi::PKCS12_DEFAULT_ITER,
|
||||
mac_iter: ffi::PKCS12_DEFAULT_ITER,
|
||||
ca: None,
|
||||
|
|
@ -92,8 +92,8 @@ pub struct ParsedPkcs12 {
|
|||
}
|
||||
|
||||
pub struct Pkcs12Builder {
|
||||
nid_key: nid::Nid,
|
||||
nid_cert: nid::Nid,
|
||||
nid_key: Nid,
|
||||
nid_cert: Nid,
|
||||
iter: c_int,
|
||||
mac_iter: c_int,
|
||||
ca: Option<Stack<X509>>,
|
||||
|
|
@ -101,13 +101,13 @@ pub struct Pkcs12Builder {
|
|||
|
||||
impl Pkcs12Builder {
|
||||
/// The encryption algorithm that should be used for the key
|
||||
pub fn key_algorithm(&mut self, nid: nid::Nid) -> &mut Self {
|
||||
pub fn key_algorithm(&mut self, nid: Nid) -> &mut Self {
|
||||
self.nid_key = nid;
|
||||
self
|
||||
}
|
||||
|
||||
/// The encryption algorithm that should be used for the cert
|
||||
pub fn cert_algorithm(&mut self, nid: nid::Nid) -> &mut Self {
|
||||
pub fn cert_algorithm(&mut self, nid: Nid) -> &mut Self {
|
||||
self.nid_cert = nid;
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue