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

Merge pull request #1661 from newAM/master

Add SSL_get_psk_identity
parents 04aa578b 7cd32cd2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -384,6 +384,8 @@ extern "C" {
            extern "C" fn(*mut SSL, *const c_char, *mut c_uchar, c_uint) -> c_uint,
        >,
    );
    pub fn SSL_get_psk_identity_hint(ssl: *const SSL) -> *const c_char;
    pub fn SSL_get_psk_identity(ssl: *const SSL) -> *const c_char;
}

extern "C" {
+30 −0
Original line number Diff line number Diff line
@@ -3007,6 +3007,36 @@ impl SslRef {
    pub fn set_mtu(&mut self, mtu: u32) -> Result<(), ErrorStack> {
        unsafe { cvt(ffi::SSL_set_mtu(self.as_ptr(), mtu as c_long) as c_int).map(|_| ()) }
    }

    /// Returns the PSK identity hint used during connection setup.
    ///
    /// May return `None` if no PSK identity hint was used during the connection setup.
    #[corresponds(SSL_get_psk_identity_hint)]
    #[cfg(not(osslconf = "OPENSSL_NO_PSK"))]
    pub fn psk_identity_hint(&self) -> Option<&[u8]> {
        unsafe {
            let ptr = ffi::SSL_get_psk_identity_hint(self.as_ptr());
            if ptr.is_null() {
                None
            } else {
                Some(CStr::from_ptr(ptr).to_bytes())
            }
        }
    }

    /// Returns the PSK identity used during connection setup.
    #[corresponds(SSL_get_psk_identity)]
    #[cfg(not(osslconf = "OPENSSL_NO_PSK"))]
    pub fn psk_identity(&self) -> Option<&[u8]> {
        unsafe {
            let ptr = ffi::SSL_get_psk_identity(self.as_ptr());
            if ptr.is_null() {
                None
            } else {
                Some(CStr::from_ptr(ptr).to_bytes())
            }
        }
    }
}

/// An SSL stream midway through the handshake process.