cbor: drop std feature, use core in tests (#327)

This commit is contained in:
David Drysdale
2021-06-16 13:40:18 +00:00
committed by GitHub
parent 77f6db6110
commit f2812e4fe2
10 changed files with 38 additions and 39 deletions

View File

@@ -29,10 +29,10 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --manifest-path libraries/cbor/Cargo.toml --release --features std args: --manifest-path libraries/cbor/Cargo.toml --release
- name: Unit testing of CBOR library (debug mode) - name: Unit testing of CBOR library (debug mode)
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --manifest-path libraries/cbor/Cargo.toml --features std args: --manifest-path libraries/cbor/Cargo.toml

View File

@@ -24,7 +24,7 @@ subtle = { version = "2.2", default-features = false, features = ["nightly"] }
debug_allocations = ["lang_items/debug_allocations"] debug_allocations = ["lang_items/debug_allocations"]
debug_ctap = ["libtock_drivers/debug_ctap"] debug_ctap = ["libtock_drivers/debug_ctap"]
panic_console = ["lang_items/panic_console"] panic_console = ["lang_items/panic_console"]
std = ["cbor/std", "crypto/std", "lang_items/std", "persistent_store/std"] std = ["crypto/std", "lang_items/std", "persistent_store/std"]
verbose = ["debug_ctap", "libtock_drivers/verbose_usb"] verbose = ["debug_ctap", "libtock_drivers/verbose_usb"]
with_ctap1 = ["crypto/with_ctap1"] with_ctap1 = ["crypto/with_ctap1"]
with_nfc = ["libtock_drivers/with_nfc"] with_nfc = ["libtock_drivers/with_nfc"]

View File

@@ -9,6 +9,6 @@ edition = "2018"
arrayref = "0.3.6" arrayref = "0.3.6"
libtock_drivers = { path = "../../third_party/libtock-drivers" } libtock_drivers = { path = "../../third_party/libtock-drivers" }
crypto = { path = "../../libraries/crypto", features = ['std'] } crypto = { path = "../../libraries/crypto", features = ['std'] }
cbor = { path = "../../libraries/cbor", features = ['std'] } cbor = { path = "../../libraries/cbor" }
ctap2 = { path = "../..", features = ['std'] } ctap2 = { path = "../..", features = ['std'] }
lang_items = { path = "../../third_party/lang-items", features = ['std'] } lang_items = { path = "../../third_party/lang-items", features = ['std'] }

View File

@@ -10,6 +10,3 @@ license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
[features]
std = []

View File

@@ -12,11 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![cfg_attr(not(feature = "std"), no_std)] #![no_std]
extern crate alloc; extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
pub mod macros; pub mod macros;
pub mod reader; pub mod reader;

View File

@@ -352,6 +352,7 @@ macro_rules! cbor_bytes_lit {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::super::values::{SimpleValue, Value}; use super::super::values::{SimpleValue, Value};
use alloc::{string::String, vec, vec::Vec};
#[test] #[test]
fn test_cbor_simple_values() { fn test_cbor_simple_values() {
@@ -373,8 +374,8 @@ mod test {
assert_eq!(cbor_int!(1), Value::Unsigned(1)); assert_eq!(cbor_int!(1), Value::Unsigned(1));
assert_eq!(cbor_int!(123456), Value::Unsigned(123456)); assert_eq!(cbor_int!(123456), Value::Unsigned(123456));
assert_eq!( assert_eq!(
cbor_int!(std::i64::MAX), cbor_int!(core::i64::MAX),
Value::Unsigned(std::i64::MAX as u64) Value::Unsigned(core::i64::MAX as u64)
); );
} }
@@ -382,34 +383,34 @@ mod test {
fn test_cbor_int_negative() { fn test_cbor_int_negative() {
assert_eq!(cbor_int!(-1), Value::Negative(-1)); assert_eq!(cbor_int!(-1), Value::Negative(-1));
assert_eq!(cbor_int!(-123456), Value::Negative(-123456)); assert_eq!(cbor_int!(-123456), Value::Negative(-123456));
assert_eq!(cbor_int!(std::i64::MIN), Value::Negative(std::i64::MIN)); assert_eq!(cbor_int!(core::i64::MIN), Value::Negative(core::i64::MIN));
} }
#[test] #[test]
fn test_cbor_int_literals() { fn test_cbor_int_literals() {
let a = cbor_array![ let a = cbor_array![
std::i64::MIN, core::i64::MIN,
std::i32::MIN, core::i32::MIN,
-123456, -123456,
-1, -1,
0, 0,
1, 1,
123456, 123456,
std::i32::MAX, core::i32::MAX,
std::i64::MAX, core::i64::MAX,
std::u64::MAX, core::u64::MAX,
]; ];
let b = Value::Array(vec![ let b = Value::Array(vec![
Value::Negative(std::i64::MIN), Value::Negative(core::i64::MIN),
Value::Negative(std::i32::MIN as i64), Value::Negative(core::i32::MIN as i64),
Value::Negative(-123456), Value::Negative(-123456),
Value::Negative(-1), Value::Negative(-1),
Value::Unsigned(0), Value::Unsigned(0),
Value::Unsigned(1), Value::Unsigned(1),
Value::Unsigned(123456), Value::Unsigned(123456),
Value::Unsigned(std::i32::MAX as u64), Value::Unsigned(core::i32::MAX as u64),
Value::Unsigned(std::i64::MAX as u64), Value::Unsigned(core::i64::MAX as u64),
Value::Unsigned(std::u64::MAX), Value::Unsigned(core::u64::MAX),
]); ]);
assert_eq!(a, b); assert_eq!(a, b);
} }

View File

@@ -208,6 +208,7 @@ mod test {
cbor_array, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_true, cbor_array, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_true,
cbor_undefined, cbor_undefined,
}; };
use alloc::vec;
#[test] #[test]
fn test_read_unsigned() { fn test_read_unsigned() {
@@ -227,7 +228,7 @@ mod test {
vec![0x1B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00], vec![0x1B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00],
), ),
( (
std::i64::MAX, core::i64::MAX,
vec![0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], vec![0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
), ),
]; ];
@@ -289,7 +290,7 @@ mod test {
(-1000000, vec![0x3A, 0x00, 0x0F, 0x42, 0x3F]), (-1000000, vec![0x3A, 0x00, 0x0F, 0x42, 0x3F]),
(-4294967296, vec![0x3A, 0xFF, 0xFF, 0xFF, 0xFF]), (-4294967296, vec![0x3A, 0xFF, 0xFF, 0xFF, 0xFF]),
( (
std::i64::MIN, core::i64::MIN,
vec![0x3B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], vec![0x3B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
), ),
]; ];
@@ -326,7 +327,7 @@ mod test {
("\"\\", vec![0x62, 0x22, 0x5C]), ("\"\\", vec![0x62, 0x22, 0x5C]),
("ü", vec![0x62, 0xC3, 0xBC]), ("ü", vec![0x62, 0xC3, 0xBC]),
( (
std::str::from_utf8(&unicode_3byte).unwrap(), core::str::from_utf8(&unicode_3byte).unwrap(),
vec![0x63, 0xE6, 0xB0, 0xB4], vec![0x63, 0xE6, 0xB0, 0xB4],
), ),
("𐅑", vec![0x64, 0xF0, 0x90, 0x85, 0x91]), ("𐅑", vec![0x64, 0xF0, 0x90, 0x85, 0x91]),

View File

@@ -232,6 +232,7 @@ where
mod test { mod test {
use super::*; use super::*;
use crate::{cbor_array, cbor_bool, cbor_bytes, cbor_int, cbor_map, cbor_text}; use crate::{cbor_array, cbor_bool, cbor_bytes, cbor_int, cbor_map, cbor_text};
use alloc::vec;
#[test] #[test]
fn test_value_ordering() { fn test_value_ordering() {
@@ -239,14 +240,14 @@ mod test {
assert!(cbor_int!(23) < cbor_int!(24)); assert!(cbor_int!(23) < cbor_int!(24));
assert!(cbor_int!(24) < cbor_int!(1000)); assert!(cbor_int!(24) < cbor_int!(1000));
assert!(cbor_int!(1000) < cbor_int!(1000000)); assert!(cbor_int!(1000) < cbor_int!(1000000));
assert!(cbor_int!(1000000) < cbor_int!(std::i64::MAX)); assert!(cbor_int!(1000000) < cbor_int!(core::i64::MAX));
assert!(cbor_int!(std::i64::MAX) < cbor_int!(-1)); assert!(cbor_int!(core::i64::MAX) < cbor_int!(-1));
assert!(cbor_int!(-1) < cbor_int!(-23)); assert!(cbor_int!(-1) < cbor_int!(-23));
assert!(cbor_int!(-23) < cbor_int!(-24)); assert!(cbor_int!(-23) < cbor_int!(-24));
assert!(cbor_int!(-24) < cbor_int!(-1000)); assert!(cbor_int!(-24) < cbor_int!(-1000));
assert!(cbor_int!(-1000) < cbor_int!(-1000000)); assert!(cbor_int!(-1000) < cbor_int!(-1000000));
assert!(cbor_int!(-1000000) < cbor_int!(std::i64::MIN)); assert!(cbor_int!(-1000000) < cbor_int!(core::i64::MIN));
assert!(cbor_int!(std::i64::MIN) < cbor_bytes!(vec![])); assert!(cbor_int!(core::i64::MIN) < cbor_bytes!(vec![]));
assert!(cbor_bytes!(vec![]) < cbor_bytes!(vec![0x00])); assert!(cbor_bytes!(vec![]) < cbor_bytes!(vec![0x00]));
assert!(cbor_bytes!(vec![0x00]) < cbor_bytes!(vec![0x01])); assert!(cbor_bytes!(vec![0x00]) < cbor_bytes!(vec![0x01]));
assert!(cbor_bytes!(vec![0x01]) < cbor_bytes!(vec![0xFF])); assert!(cbor_bytes!(vec![0x01]) < cbor_bytes!(vec![0xFF]));

View File

@@ -101,6 +101,7 @@ mod test {
cbor_array, cbor_array_vec, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_array, cbor_array_vec, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null,
cbor_text, cbor_true, cbor_undefined, cbor_text, cbor_true, cbor_undefined,
}; };
use alloc::vec;
fn write_return(value: Value) -> Option<Vec<u8>> { fn write_return(value: Value) -> Option<Vec<u8>> {
let mut encoded_cbor = Vec::new(); let mut encoded_cbor = Vec::new();
@@ -129,7 +130,7 @@ mod test {
vec![0x1B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00], vec![0x1B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00],
), ),
( (
std::i64::MAX, core::i64::MAX,
vec![0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], vec![0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
), ),
]; ];
@@ -154,7 +155,7 @@ mod test {
vec![0x3B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00], vec![0x3B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00],
), ),
( (
std::i64::MIN, core::i64::MIN,
vec![0x3B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], vec![0x3B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
), ),
]; ];
@@ -187,7 +188,7 @@ mod test {
("\"\\", vec![0x62, 0x22, 0x5C]), ("\"\\", vec![0x62, 0x22, 0x5C]),
("ü", vec![0x62, 0xC3, 0xBC]), ("ü", vec![0x62, 0xC3, 0xBC]),
( (
std::str::from_utf8(&unicode_3byte).unwrap(), core::str::from_utf8(&unicode_3byte).unwrap(),
vec![0x63, 0xE6, 0xB0, 0xB4], vec![0x63, 0xE6, 0xB0, 0xB4],
), ),
("𐅑", vec![0x64, 0xF0, 0x90, 0x85, 0x91]), ("𐅑", vec![0x64, 0xF0, 0x90, 0x85, 0x91]),
@@ -217,13 +218,13 @@ mod test {
0 => "a", 0 => "a",
23 => "b", 23 => "b",
24 => "c", 24 => "c",
std::u8::MAX as i64 => "d", core::u8::MAX as i64 => "d",
256 => "e", 256 => "e",
std::u16::MAX as i64 => "f", core::u16::MAX as i64 => "f",
65536 => "g", 65536 => "g",
std::u32::MAX as i64 => "h", core::u32::MAX as i64 => "h",
4294967296_i64 => "i", 4294967296_i64 => "i",
std::i64::MAX => "j", core::i64::MAX => "j",
-1 => "k", -1 => "k",
-24 => "l", -24 => "l",
-25 => "m", -25 => "m",
@@ -232,7 +233,7 @@ mod test {
-65537 => "p", -65537 => "p",
-4294967296_i64 => "q", -4294967296_i64 => "q",
-4294967297_i64 => "r", -4294967297_i64 => "r",
std::i64::MIN => "s", core::i64::MIN => "s",
b"a" => 2, b"a" => 2,
b"bar" => 3, b"bar" => 3,
b"foo" => 4, b"foo" => 4,

View File

@@ -24,5 +24,5 @@ serde_json = { version = "1.0", optional = true }
regex = { version = "1", optional = true } regex = { version = "1", optional = true }
[features] [features]
std = ["cbor/std", "hex", "rand", "ring", "untrusted", "serde", "serde_json", "regex"] std = ["hex", "rand", "ring", "untrusted", "serde", "serde_json", "regex"]
with_ctap1 = [] with_ctap1 = []