From caed948eb70d694c4638e7102a661b6da1658809 Mon Sep 17 00:00:00 2001 From: Raoul Strackx Date: Fri, 19 Jan 2024 15:28:06 +0100 Subject: [PATCH] Test Signer::new() function --- intel-sgx/sgxs/Cargo.toml | 2 +- intel-sgx/sgxs/src/sigstruct.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/intel-sgx/sgxs/Cargo.toml b/intel-sgx/sgxs/Cargo.toml index 408790d8..3d9e421e 100644 --- a/intel-sgx/sgxs/Cargo.toml +++ b/intel-sgx/sgxs/Cargo.toml @@ -29,5 +29,5 @@ sha2 = { version = "0.8", optional = true } # MIT OR Apache-2.0 [features] crypto-openssl = ["openssl", "openssl-sys", "foreign-types"] -[dev-dependencies] +[target.'cfg(not(target_env = "sgx"))'.dev-dependencies] crypto-hash = "0.3" # MIT diff --git a/intel-sgx/sgxs/src/sigstruct.rs b/intel-sgx/sgxs/src/sigstruct.rs index 3d28a88e..b0d8867b 100644 --- a/intel-sgx/sgxs/src/sigstruct.rs +++ b/intel-sgx/sgxs/src/sigstruct.rs @@ -246,3 +246,17 @@ pub fn read(reader: &mut R) -> IoResult { reader.read_exact(&mut buf)?; Sigstruct::try_copy_from(&buf).ok_or_else(|| unreachable!()) } + +#[cfg(test)] +mod tests { + use super::{EnclaveHash, Signer}; + + #[test] + fn signer() { + let signer = Signer::new(EnclaveHash::new([0; 32])); + assert!(signer.date & 0xff <= 0x31); // day + assert!(signer.date & 0xff00 <= 0x1200); // month + assert!(signer.date & 0xffff0000 >= 0x20240000); // year + assert!(signer.date & 0xffff0000 <= 0x20500000); + } +}