Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bindings] Fix constant name #3410

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions bindings/rust/s2n-tls/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ impl Builder {
s2n_config_append_protocol_preference(
self.as_mut_ptr(),
protocol.as_ptr(),
protocol.len().try_into().map_err(|_| Error::InvalidInput)?,
protocol
.len()
.try_into()
.map_err(|_| Error::INVALID_INPUT)?,
)
.into_result()
}?;
Expand All @@ -232,14 +235,14 @@ impl Builder {
}

pub fn add_dhparams(&mut self, pem: &[u8]) -> Result<&mut Self, Error> {
let cstring = CString::new(pem).map_err(|_| Error::InvalidInput)?;
let cstring = CString::new(pem).map_err(|_| Error::INVALID_INPUT)?;
unsafe { s2n_config_add_dhparams(self.as_mut_ptr(), cstring.as_ptr()).into_result() }?;
Ok(self)
}

pub fn load_pem(&mut self, certificate: &[u8], private_key: &[u8]) -> Result<&mut Self, Error> {
let certificate = CString::new(certificate).map_err(|_| Error::InvalidInput)?;
let private_key = CString::new(private_key).map_err(|_| Error::InvalidInput)?;
let certificate = CString::new(certificate).map_err(|_| Error::INVALID_INPUT)?;
let private_key = CString::new(private_key).map_err(|_| Error::INVALID_INPUT)?;
unsafe {
s2n_config_add_cert_chain_and_key(
self.as_mut_ptr(),
Expand All @@ -252,7 +255,7 @@ impl Builder {
}

pub fn trust_pem(&mut self, certificate: &[u8]) -> Result<&mut Self, Error> {
let certificate = CString::new(certificate).map_err(|_| Error::InvalidInput)?;
let certificate = CString::new(certificate).map_err(|_| Error::INVALID_INPUT)?;
unsafe {
s2n_config_add_pem_to_trust_store(self.as_mut_ptr(), certificate.as_ptr()).into_result()
}?;
Expand All @@ -267,8 +270,8 @@ impl Builder {
fn to_cstr(input: Option<&Path>) -> Result<Option<CString>, Error> {
Ok(match input {
Some(input) => {
let string = input.to_str().ok_or(Error::InvalidInput)?;
let cstring = CString::new(string).map_err(|_| Error::InvalidInput)?;
let string = input.to_str().ok_or(Error::INVALID_INPUT)?;
let cstring = CString::new(string).map_err(|_| Error::INVALID_INPUT)?;
Some(cstring)
}
None => None,
Expand Down Expand Up @@ -329,7 +332,7 @@ impl Builder {
// which allows certificate chains to be shared across configs.
// In that case, we'll need additional guard rails either in these bindings or in the underlying C.
pub fn set_ocsp_data(&mut self, data: &[u8]) -> Result<&mut Self, Error> {
let size: u32 = data.len().try_into().map_err(|_| Error::InvalidInput)?;
let size: u32 = data.len().try_into().map_err(|_| Error::INVALID_INPUT)?;
unsafe {
s2n_config_set_extension_data(
self.as_mut_ptr(),
Expand Down
15 changes: 9 additions & 6 deletions bindings/rust/s2n-tls/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! static_const_str {
($c_chars:expr) => {
unsafe { CStr::from_ptr($c_chars) }
.to_str()
.map_err(|_| Error::InvalidInput)
.map_err(|_| Error::INVALID_INPUT)
};
}

Expand Down Expand Up @@ -275,7 +275,10 @@ impl Connection {
s2n_connection_append_protocol_preference(
self.connection.as_ptr(),
protocol.as_ptr(),
protocol.len().try_into().map_err(|_| Error::InvalidInput)?,
protocol
.len()
.try_into()
.map_err(|_| Error::INVALID_INPUT)?,
)
.into_result()
}?;
Expand Down Expand Up @@ -400,7 +403,7 @@ impl Connection {
/// Returns the number of bytes written, and may indicate a partial write.
pub fn poll_send(&mut self, buf: &[u8]) -> Poll<Result<usize, Error>> {
let mut blocked = s2n_blocked_status::NOT_BLOCKED;
let buf_len: isize = buf.len().try_into().map_err(|_| Error::InvalidInput)?;
let buf_len: isize = buf.len().try_into().map_err(|_| Error::INVALID_INPUT)?;
let buf_ptr = buf.as_ptr() as *const ::libc::c_void;
unsafe { s2n_send(self.connection.as_ptr(), buf_ptr, buf_len, &mut blocked).into_poll() }
}
Expand All @@ -412,7 +415,7 @@ impl Connection {
/// 0 bytes returned indicates EOF due to connection closure.
pub fn poll_recv(&mut self, buf: &mut [u8]) -> Poll<Result<usize, Error>> {
let mut blocked = s2n_blocked_status::NOT_BLOCKED;
let buf_len: isize = buf.len().try_into().map_err(|_| Error::InvalidInput)?;
let buf_len: isize = buf.len().try_into().map_err(|_| Error::INVALID_INPUT)?;
let buf_ptr = buf.as_ptr() as *mut ::libc::c_void;
unsafe { s2n_recv(self.connection.as_ptr(), buf_ptr, buf_len, &mut blocked).into_poll() }
}
Expand Down Expand Up @@ -453,7 +456,7 @@ impl Connection {

/// Sets the server name value for the connection
pub fn set_server_name(&mut self, server_name: &str) -> Result<&mut Self, Error> {
let server_name = std::ffi::CString::new(server_name).map_err(|_| Error::InvalidInput)?;
let server_name = std::ffi::CString::new(server_name).map_err(|_| Error::INVALID_INPUT)?;
unsafe {
s2n_set_server_name(self.connection.as_ptr(), server_name.as_ptr()).into_result()
}?;
Expand Down Expand Up @@ -603,7 +606,7 @@ impl Connection {
s2n_connection_set_quic_transport_parameters(
self.connection.as_ptr(),
buffer.as_ptr(),
buffer.len().try_into().map_err(|_| Error::InvalidInput)?,
buffer.len().try_into().map_err(|_| Error::INVALID_INPUT)?,
)
.into_result()
}?;
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls/src/connection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<T: Pool + Clone> Builder for T {
if mode == self.mode() {
Ok(PooledConnection::new(self)?)
} else {
Err(Error::InvalidInput)
Err(Error::INVALID_INPUT)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl TryFrom<s2n_tls_version::Type> for Version {
s2n_tls_version::TLS11 => Self::TLS11,
s2n_tls_version::TLS12 => Self::TLS12,
s2n_tls_version::TLS13 => Self::TLS13,
_ => return Err(Error::InvalidInput),
_ => return Err(Error::INVALID_INPUT),
};
Ok(version)
}
Expand Down
10 changes: 3 additions & 7 deletions bindings/rust/s2n-tls/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ impl<T: Fallible> Pollable for T {
}

impl Error {
// Previously we referenced InvalidInput via Error::InvalidInput.
// Keep this naming.
// TODO: Update this + all references to all upper case.
#[allow(non_upper_case_globals)]
pub(crate) const InvalidInput: Error = Self(Context::InvalidInput);
pub(crate) const INVALID_INPUT: Error = Self(Context::InvalidInput);

pub fn new<T: Fallible>(value: T) -> Result<T::Output, Self> {
value.into_result()
Expand Down Expand Up @@ -267,11 +263,11 @@ unsafe fn cstr_to_str(v: *const c_char) -> &'static str {
impl TryFrom<std::io::Error> for Error {
type Error = Error;
fn try_from(value: std::io::Error) -> Result<Self, Self::Error> {
let io_inner = value.into_inner().ok_or(Error::InvalidInput)?;
let io_inner = value.into_inner().ok_or(Error::INVALID_INPUT)?;
io_inner
.downcast::<Self>()
.map(|error| *error)
.map_err(|_| Error::InvalidInput)
.map_err(|_| Error::INVALID_INPUT)
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls/src/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Policy {
}

pub fn from_version(version: &str) -> Result<Policy, Error> {
let cstr = CString::new(version).map_err(|_| Error::InvalidInput)?;
let cstr = CString::new(version).map_err(|_| Error::INVALID_INPUT)?;
let context = Context::Owned(cstr);
Ok(Self(context))
}
Expand Down