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