Skip to content

Commit

Permalink
set_hostname can be used with no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
eranrund committed Sep 21, 2023
1 parent 6d8fe32 commit e206d92
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions mbedtls/src/ssl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* option. This file may not be copied, modified, or distributed except
* according to those terms. */

extern crate alloc;

use core::any::Any;
use core::result::Result as StdResult;
Expand Down Expand Up @@ -144,18 +145,9 @@ impl Context {
}
}

#[cfg(not(feature = "std"))]
fn set_hostname(&mut self, hostname: Option<&str>) -> Result<()> {
match hostname {
Some(_) => Err(Error::SslBadInputData),
None => Ok(()),
}
}

#[cfg(feature = "std")]
fn set_hostname(&mut self, hostname: Option<&str>) -> Result<()> {
if let Some(s) = hostname {
let cstr = ::std::ffi::CString::new(s).map_err(|_| Error::SslBadInputData)?;
let cstr = alloc::ffi::CString::new(s).map_err(|_| Error::SslBadInputData)?;
unsafe {
ssl_set_hostname(self.into(), cstr.as_ptr())
.into_result()
Expand Down

0 comments on commit e206d92

Please sign in to comment.