#![deny(warnings)]
#![allow(unused_doc_comments)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(any(feature = "std", feature = "no_std_deps")))]
compile_error!("Either the `std` or `no_std_deps` feature needs to be enabled");
#[macro_use]
extern crate serde_derive;
#[cfg(target_env = "sgx")]
extern crate rs_libc;
#[macro_use]
mod wrapper_macros;
pub mod bignum;
mod error;
pub use crate::error::{Error, Result};
pub mod cipher;
pub mod ecp;
pub mod hash;
pub mod pk;
pub mod rng;
pub use mbedtls_platform_support::self_test;
#[cfg(any(feature = "x509", feature = "ssl", feature = "pkcs12"))]
pub mod alloc;
#[cfg(feature = "ssl")]
pub mod ssl;
#[cfg(feature = "x509")]
pub mod x509;
#[cfg(feature = "pkcs12")]
pub mod pkcs12;
pub fn zeroize(buf: &mut [u8]) {
unsafe { mbedtls_sys::platform_zeroize(buf.as_mut_ptr() as *mut mbedtls_sys::types::raw_types::c_void, buf.len()) }
}
mod private;
#[doc(hidden)]
#[cfg(sys_threading_component = "custom")]
pub mod threading;
cfg_if::cfg_if! {
if #[cfg(any(feature = "force_aesni_support", target_env = "sgx"))] {
#[doc(hidden)]
pub use mbedtls_platform_support::mbedtls_aesni_has_support;
#[doc(hidden)]
pub use mbedtls_platform_support::mbedtls_internal_aes_encrypt;
#[doc(hidden)]
pub use mbedtls_platform_support::mbedtls_internal_aes_decrypt;
}
}
#[cfg(test)]
#[path = "../tests/support/mod.rs"]
mod test_support;
#[cfg(test)]
mod mbedtls {
pub use super::*;
}
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc as rust_alloc;
#[cfg(not(feature = "std"))]
mod alloc_prelude {
#![allow(unused)]
pub(crate) use rust_alloc::borrow::Cow;
pub(crate) use rust_alloc::borrow::ToOwned;
pub(crate) use rust_alloc::boxed::Box;
pub(crate) use rust_alloc::string::String;
pub(crate) use rust_alloc::string::ToString;
pub(crate) use rust_alloc::sync::Arc;
pub(crate) use rust_alloc::vec::Vec;
}
cfg_if::cfg_if! {
if #[cfg(sys_time_component = "custom")] {
#[doc(hidden)]
pub use mbedtls_platform_support::mbedtls_platform_gmtime_r;
#[doc(hidden)]
pub use mbedtls_platform_support::mbedtls_time;
}
}
#[cfg(feature = "debug")]
pub unsafe fn set_global_debug_threshold(threshold: i32) {
mbedtls_sys::debug_set_threshold(threshold);
}
#[cfg(test)]
mod tests {
#[allow(dead_code)]
mod testtrait {
use core::marker::PhantomData;
pub struct NonImplTrait<T> {
inner: PhantomData<T>,
}
pub struct TestTrait<TraitObj: ?Sized, Type> {
non_impl: NonImplTrait<Type>,
phantom: PhantomData<*const TraitObj>,
}
pub trait Testable<T: ?Sized> {}
impl<TraitObj: ?Sized, Type> TestTrait<TraitObj, Type> {
pub fn new() -> Self {
TestTrait {
non_impl: NonImplTrait { inner: PhantomData },
phantom: PhantomData,
}
}
}
impl<TraitObj: ?Sized, Type: Testable<TraitObj>> TestTrait<TraitObj, Type> {
pub fn impls_trait(&self) -> bool {
true
}
}
impl<T> NonImplTrait<T> {
pub fn impls_trait(&self) -> bool {
false
}
}
impl<TraitObj: ?Sized, Type> core::ops::Deref for TestTrait<TraitObj, Type> {
type Target = NonImplTrait<Type>;
fn deref(&self) -> &NonImplTrait<Type> {
&self.non_impl
}
}
}
pub use testtrait::{TestTrait, Testable};
impl<T: Send> Testable<dyn Send> for T {}
impl<T: Sync> Testable<dyn Sync> for T {}
impl<T: Send + Sync> Testable<dyn Send + Sync> for T {}
}