Skip to content

Commit

Permalink
fixup Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szszszsz authored and robin-nitrokey committed Nov 29, 2023
1 parent a16f8dc commit 0684820
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 25 additions & 2 deletions src/virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ use crate::streaming::ChunkedExtension;
#[cfg(feature = "manage")]
use trussed::types::{Location, Path};

#[cfg(feature = "hmacsha256p256")]
use crate::hmacsha256p256::HmacSha256P256Extension;

#[derive(Default, Debug)]
pub struct Dispatcher {
backend: StagingBackend,
Expand All @@ -34,6 +37,14 @@ pub enum ExtensionIds {
Chunked,
#[cfg(feature = "manage")]
Manage,
#[cfg(feature = "hmacsha256p256")]
HmacShaP256,
}

#[cfg(feature = "hmacsha256p256")]
impl ExtensionId<HmacSha256P256Extension> for Dispatcher {
type Id = ExtensionIds;
const ID: ExtensionIds = ExtensionIds::HmacShaP256;
}

#[cfg(feature = "wrap-key-to-file")]
Expand Down Expand Up @@ -63,6 +74,8 @@ impl From<ExtensionIds> for u8 {
ExtensionIds::Chunked => 1,
#[cfg(feature = "manage")]
ExtensionIds::Manage => 2,
#[cfg(feature = "hmacsha256p256")]
ExtensionIds::HmacShaP256 => 2,
}
}
}
Expand All @@ -77,6 +90,8 @@ impl TryFrom<u8> for ExtensionIds {
1 => Ok(Self::Chunked),
#[cfg(feature = "manage")]
2 => Ok(Self::Manage),
#[cfg(feature = "hmacsha256p256")]
3 => Ok(Self::HmacShaP256),
_ => Err(Error::FunctionNotSupported),
}
}
Expand Down Expand Up @@ -122,7 +137,16 @@ impl ExtensionDispatch for Dispatcher {
resources,
)
}

#[cfg(feature = "hmacsha256p256")]
ExtensionIds::HmacShaP256 => {
ExtensionImpl::<HmacSha256P256Extension>::extension_request_serialized(
&mut self.backend,
&mut ctx.core,
&mut ctx.backends,
request,
resources,
)
}
#[cfg(feature = "chunked")]
ExtensionIds::Chunked => {
ExtensionImpl::<ChunkedExtension>::extension_request_serialized(
Expand All @@ -133,7 +157,6 @@ impl ExtensionDispatch for Dispatcher {
resources,
)
}

#[cfg(feature = "manage")]
ExtensionIds::Manage => ExtensionImpl::<ManageExtension>::extension_request_serialized(
&mut self.backend,
Expand Down
6 changes: 3 additions & 3 deletions tests/hmacsha256p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ use trussed_staging::hmacsha256p256::HmacSha256P256Client;

#[test]
fn hmac_inject_any() {
use trussed::types::Message;
with_ram_client("staging-tests", |mut client| {
let client = &mut client;

let key = syscall!(client.inject_any_key(
b"12345678123456781234567812345678",
Message::from_slice(b"12345678123456781234567812345678").unwrap(),
Volatile,
Kind::P256
))
.key
.unwrap();

let pk = syscall!(client.derive_p256_public_key(key, Location::Volatile)).key;
let _pk = syscall!(client.derive_p256_public_key(key, Location::Volatile)).key;

let signature =
syscall!(client.sign(Mechanism::P256, key, &[], SignatureSerialization::Raw)).signature;
assert!(signature.len() > 0);
todo!();
});
}

0 comments on commit 0684820

Please sign in to comment.