aboutsummaryrefslogtreecommitdiff
path: root/openssl
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-06 10:46:38 -0800
committerSteven Fackler <[email protected]>2016-11-06 10:46:38 -0800
commitbcb7b3f5dc58de1fa88a65f5b6ea0bda089c2aee (patch)
tree9ba6f8cb45717b7f328aee09eb6c8f3981931f17 /openssl
parentMerge pull request #513 from alexcrichton/pkg-config-error (diff)
downloadrust-openssl-bcb7b3f5dc58de1fa88a65f5b6ea0bda089c2aee.tar.xz
rust-openssl-bcb7b3f5dc58de1fa88a65f5b6ea0bda089c2aee.zip
Add accessors for cert and private key
Closes #340
Diffstat (limited to 'openssl')
-rw-r--r--openssl/src/ssl/mod.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 9a477993..16bc386b 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -762,6 +762,31 @@ impl SslContext {
}
}
+impl SslContextRef {
+ /// Returns the certificate associated with this `SslContext`, if present.
+ pub fn certificate(&self) -> Option<&X509Ref> {
+ unsafe {
+ let ptr = ffi::SSL_CTX_get0_certificate(self.as_ptr());
+ if ptr.is_null() {
+ None
+ } else {
+ Some(X509Ref::from_ptr(ptr))
+ }
+ }
+ }
+
+ /// Returns the private key associated with this `SslContext`, if present.
+ pub fn private_key(&self) -> Option<&PKeyRef> {
+ unsafe {
+ let ptr = ffi::SSL_CTX_get0_privatekey(self.as_ptr());
+ if ptr.is_null() {
+ None
+ } else {
+ Some(PKeyRef::from_ptr(ptr))
+ }
+ }
+ }
+}
pub struct CipherBits {
/// The number of secret bits used for the cipher.
@@ -955,6 +980,30 @@ impl SslRef {
}
}
+ /// Returns the certificate associated with this `Ssl`, if present.
+ pub fn certificate(&self) -> Option<&X509Ref> {
+ unsafe {
+ let ptr = ffi::SSL_get_certificate(self.as_ptr());
+ if ptr.is_null() {
+ None
+ } else {
+ Some(X509Ref::from_ptr(ptr))
+ }
+ }
+ }
+
+ /// Returns the private key associated with this `Ssl`, if present.
+ pub fn private_key(&self) -> Option<&PKeyRef> {
+ unsafe {
+ let ptr = ffi::SSL_get_privatekey(self.as_ptr());
+ if ptr.is_null() {
+ None
+ } else {
+ Some(PKeyRef::from_ptr(ptr))
+ }
+ }
+ }
+
/// Returns the name of the protocol used for the connection, e.g. "TLSv1.2", "SSLv3", etc.
pub fn version(&self) -> &'static str {
let version = unsafe {