Fix several no_std incompatibilities
This commit is contained in:
parent
bcbac965cd
commit
b4b549bb10
6 changed files with 29 additions and 17 deletions
|
@ -16,10 +16,11 @@ path = "src/lib.rs"
|
|||
|
||||
[features]
|
||||
default = ["std", "crypto_mbedtls"]
|
||||
std = []
|
||||
std = ["alloc"]
|
||||
alloc = []
|
||||
nightly = []
|
||||
crypto_openssl = ["openssl", "foreign-types", "hmac", "sha2"]
|
||||
crypto_mbedtls = ["mbedtls"]
|
||||
crypto_mbedtls = ["mbedtls", "alloc"]
|
||||
crypto_esp_mbedtls = ["esp-idf-sys"]
|
||||
crypto_rustcrypto = ["sha2", "hmac", "pbkdf2", "hkdf", "aes", "ccm", "p256", "elliptic-curve", "crypto-bigint", "x509-cert"]
|
||||
|
||||
|
@ -33,6 +34,7 @@ generic-array = "0.14.6"
|
|||
num = "0.4"
|
||||
num-derive = "0.3.3"
|
||||
num-traits = "0.2.15"
|
||||
strum = { version = "0.24", features = ["derive"], default-features = false, no-default-feature = true }
|
||||
log = { version = "0.4.17", features = ["max_level_debug", "release_max_level_debug"] }
|
||||
env_logger = { version = "0.10.0", default-features = false, features = [] }
|
||||
rand = "0.8.5"
|
||||
|
@ -44,7 +46,6 @@ owning_ref = "0.4.1"
|
|||
safemem = "0.3.3"
|
||||
chrono = { version = "0.4.23", default-features = false, features = ["clock", "std"] }
|
||||
async-channel = "1.8"
|
||||
strum = { version = "0.24", features = ["derive"], no-default-feature = true }
|
||||
|
||||
# crypto
|
||||
openssl = { git = "https://github.com/sfackler/rust-openssl", optional = true }
|
||||
|
|
|
@ -143,7 +143,7 @@ impl AccessorSubjects {
|
|||
}
|
||||
|
||||
impl Display for AccessorSubjects {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::result::Result<(), core::fmt::Error> {
|
||||
write!(f, "[")?;
|
||||
for i in self.0 {
|
||||
if is_noc_cat(i) {
|
||||
|
|
|
@ -519,8 +519,16 @@ fn encode_dn_value(
|
|||
w.oid(name, oid)?;
|
||||
match value {
|
||||
DistNameValue::Uint(v) => match expected_len {
|
||||
Some(IntToStringLen::Len16) => w.utf8str("", format!("{:016X}", v).as_str())?,
|
||||
Some(IntToStringLen::Len8) => w.utf8str("", format!("{:08X}", v).as_str())?,
|
||||
Some(IntToStringLen::Len16) => {
|
||||
let mut string = heapless::String::<32>::new();
|
||||
write!(&mut string, "{:016X}", v).unwrap();
|
||||
w.utf8str("", &string)?
|
||||
}
|
||||
Some(IntToStringLen::Len8) => {
|
||||
let mut string = heapless::String::<32>::new();
|
||||
write!(&mut string, "{:08X}", v).unwrap();
|
||||
w.utf8str("", &string)?
|
||||
}
|
||||
_ => {
|
||||
error!("Invalid encoding");
|
||||
return Err(Error::Invalid);
|
||||
|
|
|
@ -182,4 +182,5 @@ impl fmt::Display for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for Error {}
|
||||
|
|
|
@ -86,6 +86,8 @@ impl RxCtrState {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use log::info;
|
||||
|
||||
use super::RxCtrState;
|
||||
|
||||
const ENCRYPTED: bool = true;
|
||||
|
@ -194,10 +196,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn unencrypted_device_reboot() {
|
||||
println!("Sub 65532 is {:?}", 1_u16.overflowing_sub(65532));
|
||||
println!("Sub 65535 is {:?}", 1_u16.overflowing_sub(65535));
|
||||
println!("Sub 11-13 is {:?}", 11_u32.wrapping_sub(13_u32) as i32);
|
||||
println!("Sub regular is {:?}", 2000_u16.overflowing_sub(1998));
|
||||
info!("Sub 65532 is {:?}", 1_u16.overflowing_sub(65532));
|
||||
info!("Sub 65535 is {:?}", 1_u16.overflowing_sub(65535));
|
||||
info!("Sub 11-13 is {:?}", 11_u32.wrapping_sub(13_u32) as i32);
|
||||
info!("Sub regular is {:?}", 2000_u16.overflowing_sub(1998));
|
||||
let mut s = RxCtrState::new(20010);
|
||||
|
||||
assert_ndup(s.recv(20011, NOT_ENCRYPTED));
|
||||
|
|
|
@ -457,13 +457,9 @@ mod tests {
|
|||
error::Error,
|
||||
transport::{
|
||||
network::Address,
|
||||
packet::{Packet, MAX_TX_BUF_SIZE},
|
||||
session::{CloneData, SessionMode, MAX_SESSIONS},
|
||||
},
|
||||
utils::{
|
||||
epoch::{dummy_epoch, sys_epoch},
|
||||
rand::dummy_rand,
|
||||
session::{CloneData, SessionMode},
|
||||
},
|
||||
utils::{epoch::dummy_epoch, rand::dummy_rand},
|
||||
};
|
||||
|
||||
use super::{ExchangeMgr, Role};
|
||||
|
@ -526,13 +522,17 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
/// We purposefuly overflow the sessions
|
||||
/// and when the overflow happens, we confirm that
|
||||
/// - The sessions are evicted in LRU
|
||||
/// - The exchanges associated with those sessions are evicted too
|
||||
fn test_sess_evict() {
|
||||
let mut mgr = ExchangeMgr::new(sys_epoch, dummy_rand);
|
||||
use crate::transport::packet::{Packet, MAX_TX_BUF_SIZE};
|
||||
use crate::transport::session::MAX_SESSIONS;
|
||||
|
||||
let mut mgr = ExchangeMgr::new(crate::utils::epoch::sys_epoch, dummy_rand);
|
||||
|
||||
fill_sessions(&mut mgr, MAX_SESSIONS + 1);
|
||||
// Sessions are now full from local session id 1 to 16
|
||||
|
|
Loading…
Add table
Reference in a new issue