aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-02-17 13:44:21 -0800
committerSteven Fackler <[email protected]>2018-02-17 13:44:21 -0800
commit90d5f855113a30afa944829c4f19c2aa60156d82 (patch)
tree881d2d2b248d9cff2631d39f9ec372993d8f236e /openssl/src
parentMerge pull request #844 from sfackler/fix-session-clone (diff)
downloadrust-openssl-90d5f855113a30afa944829c4f19c2aa60156d82.tar.xz
rust-openssl-90d5f855113a30afa944829c4f19c2aa60156d82.zip
Add SSL_version binding
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/ssl/mod.rs42
1 files changed, 40 insertions, 2 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 096d61e5..e3e5c600 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -518,6 +518,30 @@ impl AlpnError {
pub const NOACK: AlpnError = AlpnError(ffi::SSL_TLSEXT_ERR_NOACK);
}
+/// An SSL/TLS protocol version.
+#[derive(Debug, Copy, Clone)]
+pub struct SslVersion(c_int);
+
+impl SslVersion {
+ /// SSLv3
+ pub const SSL3: SslVersion = SslVersion(ffi::SSL3_VERSION);
+
+ /// TLSv1.0
+ pub const TLS1: SslVersion = SslVersion(ffi::TLS1_VERSION);
+
+ /// TLSv1.1
+ pub const TLS1_1: SslVersion = SslVersion(ffi::TLS1_1_VERSION);
+
+ /// TLSv1.2
+ pub const TLS1_2: SslVersion = SslVersion(ffi::TLS1_2_VERSION);
+
+ /// TLSv1.3
+ ///
+ /// Requires OpenSSL 1.1.1 and the corresponding Cargo feature.
+ #[cfg(all(feature = "v111", ossl111))]
+ pub const TLS1_3: SslVersion = SslVersion(ffi::TLS1_3_VERSION);
+}
+
/// A standard implementation of protocol selection for Application Layer Protocol Negotiation
/// (ALPN).
///
@@ -1906,12 +1930,21 @@ impl SslRef {
}
}
+ /// Returns the protocol version of the session.
+ ///
+ /// This corresponds to [`SSL_version`].
+ ///
+ /// [`SSL_version`]: https://www.openssl.org/docs/manmaster/man3/SSL_version.html
+ pub fn version2(&self) -> SslVersion {
+ unsafe { SslVersion(ffi::SSL_version(self.as_ptr())) }
+ }
+
/// Returns a string describing the protocol version of the session.
///
/// This corresponds to [`SSL_get_version`].
///
/// [`SSL_get_version`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_get_version.html
- pub fn version(&self) -> &'static str {
+ pub fn version_str(&self) -> &'static str {
let version = unsafe {
let ptr = ffi::SSL_get_version(self.as_ptr());
CStr::from_ptr(ptr as *const _)
@@ -1920,6 +1953,11 @@ impl SslRef {
str::from_utf8(version.to_bytes()).unwrap()
}
+ #[deprecated(since = "0.10.4", note = "renamed to version_str")]
+ pub fn version(&self) -> &'static str {
+ self.version_str()
+ }
+
/// Returns the protocol selected via Application Layer Protocol Negotiation (ALPN).
///
/// The protocol's name is returned is an opaque sequence of bytes. It is up to the client
@@ -1953,7 +1991,7 @@ impl SslRef {
/// If this is greater than 0, the next call to `read` will not call down to the underlying
/// stream.
///
- /// This corresponds to [`SSL_pending]`.
+ /// This corresponds to [`SSL_pending`].
///
/// [`SSL_pending`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_pending.html
pub fn pending(&self) -> usize {