Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AS207960/rust-openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEnbyperor committed May 28, 2021
2 parents 15ef5e0 + 78caec6 commit c3cd5e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions openssl-sys/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ extern "C" {
pub fn SSL_stateless(s: *mut SSL) -> c_int;
pub fn SSL_connect(ssl: *mut SSL) -> c_int;
pub fn SSL_read(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int;
pub fn SSL_peek(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int;
#[cfg(ossl111)]
pub fn SSL_read_early_data(
s: *mut ::SSL,
Expand Down
8 changes: 8 additions & 0 deletions openssl/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ impl<'a> Deriver<'a> {
}
}

impl<'a> Drop for Deriver<'a> {
fn drop(&mut self) {
unsafe {
ffi::EVP_PKEY_CTX_free(self.0);
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
24 changes: 24 additions & 0 deletions openssl/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,11 @@ impl SslRef {
unsafe { ffi::SSL_read(self.as_ptr(), buf.as_ptr() as *mut c_void, len) }
}

fn peek(&mut self, buf: &mut [u8]) -> c_int {
let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int;
unsafe { ffi::SSL_peek(self.as_ptr(), buf.as_ptr() as *mut c_void, len) }
}

fn write(&mut self, buf: &[u8]) -> c_int {
let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int;
unsafe { ffi::SSL_write(self.as_ptr(), buf.as_ptr() as *const c_void, len) }
Expand Down Expand Up @@ -3704,6 +3709,25 @@ impl<S: Read + Write> SslStream<S> {
}
}

/// Reads data from the stream, without removing it from the queue.
///
/// This corresponds to [`SSL_peek`].
///
/// [`SSL_peek`]: https://www.openssl.org/docs/manmaster/man3/SSL_peek.html
pub fn ssl_peek(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
// See above for why we short-circuit on zero-length buffers
if buf.is_empty() {
return Ok(0);
}

let ret = self.ssl.peek(buf);
if ret > 0 {
Ok(ret as usize)
} else {
Err(self.make_error(ret))
}
}

/// Shuts down the session.
///
/// The shutdown process consists of two steps. The first step sends a close notify message to
Expand Down

0 comments on commit c3cd5e6

Please sign in to comment.