aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-30 10:18:09 -0700
committerGitHub <[email protected]>2016-10-30 10:18:09 -0700
commita8d328d0b494c2aab8e80f7c1b907a32c7baaeb8 (patch)
tree469c8a353b972ae937f893958c39faa3f5531792 /openssl/src/x509
parentRemove private field in ParsedPkcs12 (diff)
parentPull Curl's CA list for Windows tests (diff)
downloadrust-openssl-a8d328d0b494c2aab8e80f7c1b907a32c7baaeb8.tar.xz
rust-openssl-a8d328d0b494c2aab8e80f7c1b907a32c7baaeb8.zip
Merge pull request #496 from sfackler/connectors
Implement Connector types
Diffstat (limited to 'openssl/src/x509')
-rw-r--r--openssl/src/x509/mod.rs41
-rw-r--r--openssl/src/x509/verify.rs48
2 files changed, 32 insertions, 57 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index b92462d4..b7cbe363 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -1,4 +1,5 @@
use libc::{c_char, c_int, c_long, c_ulong, c_void};
+use std::borrow::Borrow;
use std::cmp;
use std::collections::HashMap;
use std::error::Error;
@@ -17,7 +18,7 @@ use asn1::Asn1TimeRef;
use bio::{MemBio, MemBioSlice};
use crypto::CryptoString;
use hash::MessageDigest;
-use pkey::PKey;
+use pkey::{PKey, PKeyRef};
use rand::rand_bytes;
use error::ErrorStack;
use ffi;
@@ -37,12 +38,12 @@ use ffi::{
ASN1_STRING_get0_data as ASN1_STRING_data,
};
-pub mod extension;
-
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub mod verify;
-use self::extension::{ExtensionType, Extension};
+use x509::extension::{ExtensionType, Extension};
+
+pub mod extension;
#[cfg(test)]
mod tests;
@@ -277,7 +278,7 @@ impl X509Generator {
}
/// Sets the certificate public-key, then self-sign and return it
- pub fn sign(&self, p_key: &PKey) -> Result<X509, ErrorStack> {
+ pub fn sign(&self, p_key: &PKeyRef) -> Result<X509, ErrorStack> {
ffi::init();
unsafe {
@@ -329,7 +330,7 @@ impl X509Generator {
}
/// Obtain a certificate signing request (CSR)
- pub fn request(&self, p_key: &PKey) -> Result<X509Req, ErrorStack> {
+ pub fn request(&self, p_key: &PKeyRef) -> Result<X509Req, ErrorStack> {
let cert = match self.sign(p_key) {
Ok(c) => c,
Err(x) => return Err(x),
@@ -447,6 +448,17 @@ impl X509Ref {
}
}
+impl ToOwned for X509Ref {
+ type Owned = X509;
+
+ fn to_owned(&self) -> X509 {
+ unsafe {
+ compat::X509_up_ref(self.as_ptr());
+ X509::from_ptr(self.as_ptr())
+ }
+ }
+}
+
/// An owned public key certificate.
pub struct X509(*mut ffi::X509);
@@ -491,10 +503,7 @@ impl Deref for X509 {
impl Clone for X509 {
fn clone(&self) -> X509 {
- unsafe {
- compat::X509_up_ref(self.as_ptr());
- X509::from_ptr(self.as_ptr())
- }
+ self.to_owned()
}
}
@@ -504,6 +513,18 @@ impl Drop for X509 {
}
}
+impl AsRef<X509Ref> for X509 {
+ fn as_ref(&self) -> &X509Ref {
+ &*self
+ }
+}
+
+impl Borrow<X509Ref> for X509 {
+ fn borrow(&self) -> &X509Ref {
+ &*self
+ }
+}
+
pub struct X509NameRef(Opaque);
impl X509NameRef {
diff --git a/openssl/src/x509/verify.rs b/openssl/src/x509/verify.rs
index 77095edc..8cb123e6 100644
--- a/openssl/src/x509/verify.rs
+++ b/openssl/src/x509/verify.rs
@@ -2,50 +2,4 @@
//!
//! Requires the `v102` or `v110` features and OpenSSL 1.0.2 or 1.1.0.
-use libc::c_uint;
-use ffi;
-
-use cvt;
-use error::ErrorStack;
-use opaque::Opaque;
-
-bitflags! {
- pub flags X509CheckFlags: c_uint {
- const X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT = ffi::X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT,
- const X509_CHECK_FLAG_NO_WILDCARDS = ffi::X509_CHECK_FLAG_NO_WILDCARDS,
- const X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS = ffi::X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS,
- const X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS = ffi::X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS,
- const X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS
- = ffi::X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS,
- /// Requires the `v110` feature and OpenSSL 1.1.0.
- #[cfg(all(feature = "v110", ossl110))]
- const X509_CHECK_FLAG_NEVER_CHECK_SUBJECT = ffi::X509_CHECK_FLAG_NEVER_CHECK_SUBJECT,
- }
-}
-
-pub struct X509VerifyParamRef(Opaque);
-
-impl X509VerifyParamRef {
- pub unsafe fn from_ptr_mut<'a>(ptr: *mut ffi::X509_VERIFY_PARAM) -> &'a mut X509VerifyParamRef {
- &mut *(ptr as *mut _)
- }
-
- pub fn as_ptr(&self) -> *mut ffi::X509_VERIFY_PARAM {
- self as *const _ as *mut _
- }
-
- pub fn set_hostflags(&mut self, hostflags: X509CheckFlags) {
- unsafe {
- ffi::X509_VERIFY_PARAM_set_hostflags(self.as_ptr(), hostflags.bits);
- }
- }
-
- pub fn set_host(&mut self, host: &str) -> Result<(), ErrorStack> {
- unsafe {
- cvt(ffi::X509_VERIFY_PARAM_set1_host(self.as_ptr(),
- host.as_ptr() as *const _,
- host.len()))
- .map(|_| ())
- }
- }
-}
+pub use ::verify::*;