summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Saunders <ben.e.saunders@gmail.com>2018-04-29 01:54:16 -0700
committerBenjamin Saunders <ben.e.saunders@gmail.com>2018-04-29 01:54:16 -0700
commit47431f66bb8c0657475261321e0a947e10c8e93d (patch)
treedeba44c1dc58ed6e0fc99a3f36b64465b9560a1d
parent6f59406067f98e170b17175f208836b12d7126df (diff)
downloadrust-openssl-47431f66bb8c0657475261321e0a947e10c8e93d.zip
Expose SslSession <-> DER conversion
-rw-r--r--openssl-sys/src/lib.rs3
-rw-r--r--openssl/src/ssl/mod.rs23
2 files changed, 26 insertions, 0 deletions
diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs
index 8ebcb187..d7f09cec 100644
--- a/openssl-sys/src/lib.rs
+++ b/openssl-sys/src/lib.rs
@@ -2635,6 +2635,9 @@ extern "C" {
pub fn SSL_SESSION_free(s: *mut SSL_SESSION);
pub fn SSL_SESSION_get_id(s: *const SSL_SESSION, len: *mut c_uint) -> *const c_uchar;
+ pub fn d2i_SSL_SESSION(a: *mut *mut SSL_SESSION, pp: *mut *const c_uchar, len: c_long) -> *mut SSL_SESSION;
+ pub fn i2d_SSL_SESSION(s: *mut SSL_SESSION, pp: *mut *mut c_uchar) -> c_int;
+
#[cfg(not(ossl101))]
pub fn SSL_CTX_set_alpn_protos(s: *mut SSL_CTX, data: *const c_uchar, len: c_uint) -> c_int;
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 0f9e8935..ce98b18f 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -1914,6 +1914,19 @@ impl Clone for SslSession {
}
}
+impl SslSession {
+ from_der! {
+ /// Deserializes a DER-encoded session structure.
+ ///
+ /// This corresponds to [`d2i_SSL_SESSION`].
+ ///
+ /// [`d2i_SSL_SESSION`]: https://www.openssl.org/docs/man1.0.2/ssl/d2i_SSL_SESSION.html
+ from_der,
+ SslSession,
+ ffi::d2i_SSL_SESSION
+ }
+}
+
impl ToOwned for SslSessionRef {
type Owned = SslSession;
@@ -1958,6 +1971,16 @@ impl SslSessionRef {
pub fn master_key(&self, buf: &mut [u8]) -> usize {
unsafe { compat::SSL_SESSION_get_master_key(self.as_ptr(), buf.as_mut_ptr(), buf.len()) }
}
+
+ to_der! {
+ /// Serializes the session into a DER-encoded structure.
+ ///
+ /// This corresponds to [`i2d_SSL_SESSION`].
+ ///
+ /// [`i2d_SSL_SESSION`]: https://www.openssl.org/docs/man1.0.2/ssl/i2d_SSL_SESSION.html
+ to_der,
+ ffi::i2d_SSL_SESSION
+ }
}
foreign_type! {