Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart committed Apr 26, 2022
1 parent 2f4cc45 commit 182d61f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions bindings/rust/s2n-tls/src/raw/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::raw::{
security,
};
use core::{
convert::TryInto,
convert::{TryFrom, TryInto},
fmt,
ptr::NonNull,
task::{Poll, Waker},
Expand Down Expand Up @@ -58,9 +58,9 @@ impl From<Mode> for s2n_mode::Type {
}
}

#[non_exhaustive]
#[derive(Debug, PartialEq)]
pub enum Version {
Unknown,
SSLV2,
SSLV3,
TLS10,
Expand All @@ -69,17 +69,20 @@ pub enum Version {
TLS13,
}

impl From<s2n_tls_version::Type> for Version {
fn from(input: s2n_tls_version::Type) -> Self {
match input {
impl TryFrom<s2n_tls_version::Type> for Version {
type Error = Error;

fn try_from(input: s2n_tls_version::Type) -> Result<Self, Self::Error> {
let version = match input {
s2n_tls_version::SSLV2 => Self::SSLV2,
s2n_tls_version::SSLV3 => Self::SSLV3,
s2n_tls_version::TLS10 => Self::TLS10,
s2n_tls_version::TLS11 => Self::TLS11,
s2n_tls_version::TLS12 => Self::TLS12,
s2n_tls_version::TLS13 => Self::TLS13,
_ => Self::Unknown,
}
_ => return Err(Error::InvalidInput),
};
Ok(version)
}
}

Expand Down Expand Up @@ -463,10 +466,10 @@ impl Connection {
}

pub fn actual_protocol_version(&self) -> Result<Version, Error> {
let version: i32 = unsafe {
let version = unsafe {
s2n_connection_get_actual_protocol_version(self.connection.as_ptr()).into_result()?
};
Ok(version.into())
version.try_into()
}

pub fn handshake_type(&self) -> Result<&str, Error> {
Expand Down
1 change: 1 addition & 0 deletions bindings/rust/s2n-tls/src/raw/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use libc::c_char;
use s2n_tls_sys::*;
use std::ffi::CStr;

#[non_exhaustive]
#[derive(Debug, PartialEq)]
pub enum ErrorType {
UnknownErrorType,
Expand Down

0 comments on commit 182d61f

Please sign in to comment.