Unverified Commit 6bc52f07 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #927 from sfackler/move-prot-accessors

Move proto version accessors to SslContextRef
parents a2be3535 b976b5fd
Loading
Loading
Loading
Loading
+52 −44
Original line number Diff line number Diff line
@@ -1057,50 +1057,6 @@ impl SslContextBuilder {
        }
    }

    /// Gets the minimum supported protocol version.
    ///
    /// A value of `None` indicates that all versions down the the lowest version supported by
    /// OpenSSL are enabled.
    ///
    /// This corresponds to [`SSL_CTX_get_min_proto_version`].
    ///
    /// Requires OpenSSL 1.1.0g or LibreSSL 2.7.0 or newer.
    ///
    /// [`SSL_CTX_get_min_proto_version`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_min_proto_version.html
    #[cfg(any(ossl110g, libressl270))]
    pub fn min_proto_version(&mut self) -> Option<SslVersion> {
        unsafe {
            let r = ffi::SSL_CTX_get_min_proto_version(self.as_ptr());
            if r == 0 {
                None
            } else {
                Some(SslVersion(r))
            }
        }
    }

    /// Gets the maximum supported protocol version.
    ///
    /// A value of `None` indicates that all versions down the the highest version supported by
    /// OpenSSL are enabled.
    ///
    /// This corresponds to [`SSL_CTX_get_max_proto_version`].
    ///
    /// Requires OpenSSL 1.1.0g or LibreSSL 2.7.0 or newer.
    ///
    /// [`SSL_CTX_get_max_proto_version`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_min_proto_version.html
    #[cfg(any(ossl110g, libressl270))]
    pub fn max_proto_version(&mut self) -> Option<SslVersion> {
        unsafe {
            let r = ffi::SSL_CTX_get_max_proto_version(self.as_ptr());
            if r == 0 {
                None
            } else {
                Some(SslVersion(r))
            }
        }
    }

    /// Sets the protocols to sent to the server for Application Layer Protocol Negotiation (ALPN).
    ///
    /// The input must be in ALPN "wire format". It consists of a sequence of supported protocol
@@ -1496,6 +1452,14 @@ impl SslContextBuilder {
    }
}

impl Deref for SslContextBuilder {
    type Target = SslContextRef;

    fn deref(&self) -> &SslContextRef {
        &self.0
    }
}

foreign_type_and_impl_send_sync! {
    type CType = ffi::SSL_CTX;
    fn drop = ffi::SSL_CTX_free;
@@ -1644,6 +1608,50 @@ impl SslContextRef {
            }
        }
    }

    /// Gets the minimum supported protocol version.
    ///
    /// A value of `None` indicates that all versions down the the lowest version supported by
    /// OpenSSL are enabled.
    ///
    /// This corresponds to [`SSL_CTX_get_min_proto_version`].
    ///
    /// Requires OpenSSL 1.1.0g or LibreSSL 2.7.0 or newer.
    ///
    /// [`SSL_CTX_get_min_proto_version`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_min_proto_version.html
    #[cfg(any(ossl110g, libressl270))]
    pub fn min_proto_version(&self) -> Option<SslVersion> {
        unsafe {
            let r = ffi::SSL_CTX_get_min_proto_version(self.as_ptr());
            if r == 0 {
                None
            } else {
                Some(SslVersion(r))
            }
        }
    }

    /// Gets the maximum supported protocol version.
    ///
    /// A value of `None` indicates that all versions down the the highest version supported by
    /// OpenSSL are enabled.
    ///
    /// This corresponds to [`SSL_CTX_get_max_proto_version`].
    ///
    /// Requires OpenSSL 1.1.0g or LibreSSL 2.7.0 or newer.
    ///
    /// [`SSL_CTX_get_max_proto_version`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_min_proto_version.html
    #[cfg(any(ossl110g, libressl270))]
    pub fn max_proto_version(&self) -> Option<SslVersion> {
        unsafe {
            let r = ffi::SSL_CTX_get_max_proto_version(self.as_ptr());
            if r == 0 {
                None
            } else {
                Some(SslVersion(r))
            }
        }
    }
}

/// Information about the state of a cipher.