From 10dd4d929b4a8a078d9be1e28121fafcd06ef418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 4 Nov 2022 10:50:16 +0100 Subject: [PATCH] Remove const generic in state --- src/dispatch.rs | 2 +- src/lib.rs | 16 ++++++++-------- src/state.rs | 27 +++++++++++---------------- src/tlv.rs | 1 + src/vpicc.rs | 5 ++--- tests/setup/mod.rs | 3 ++- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/dispatch.rs b/src/dispatch.rs index a6f9cd7..0928899 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -4,7 +4,7 @@ use apdu_dispatch::{app::App, command, response, Command}; use trussed::client; #[cfg(feature = "apdu-dispatch")] -impl App<{ command::SIZE }, { response::SIZE }> for Authenticator +impl App<{ command::SIZE }, { response::SIZE }> for Authenticator where T: client::Client + client::Ed255 + client::Tdes, { diff --git a/src/lib.rs b/src/lib.rs index 3985bb6..fcef2d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,18 +41,18 @@ pub type Result = iso7816::Result<()>; /// The `C` parameter is necessary, as PIV includes command sequences, /// where we need to store the previous command, so we need to know how /// much space to allocate. -pub struct Authenticator { - state: state::State, +pub struct Authenticator { + state: state::State, trussed: T, } -impl iso7816::App for Authenticator { +impl iso7816::App for Authenticator { fn aid(&self) -> iso7816::Aid { crate::constants::PIV_AID } } -impl Authenticator +impl Authenticator where T: client::Client + client::Ed255 + client::Tdes, { @@ -87,7 +87,7 @@ where Ok(()) } - pub fn respond( + pub fn respond( &mut self, command: &iso7816::Command, reply: &mut Data, @@ -316,7 +316,7 @@ where todo!() } - pub fn generate_asymmetric_keypair( + pub fn generate_asymmetric_keypair( &mut self, command: &iso7816::Command, reply: &mut Data, @@ -453,7 +453,7 @@ where Ok(()) } - pub fn put_data(&mut self, command: &iso7816::Command) -> Result { + pub fn put_data(&mut self, command: &iso7816::Command) -> Result { info!("PutData"); if command.p1 != 0x3f || command.p2 != 0xff { return Err(Status::IncorrectP1OrP2Parameter); @@ -627,7 +627,7 @@ where Ok(()) } - pub fn yubico_piv_extension( + pub fn yubico_piv_extension( &mut self, command: &iso7816::Command, instruction: YubicoPivExtension, diff --git a/src/state.rs b/src/state.rs index c22dad7..0ad84ef 100644 --- a/src/state.rs +++ b/src/state.rs @@ -148,16 +148,13 @@ pub struct Keys { } #[derive(Debug, Default, Eq, PartialEq)] -pub struct State { - pub runtime: Runtime, +pub struct State { + pub runtime: Runtime, pub persistent: Option, } -impl State { - pub fn load( - &mut self, - client: &mut impl trussed::Client, - ) -> Result, Status> { +impl State { + pub fn load(&mut self, client: &mut impl trussed::Client) -> Result, Status> { if self.persistent.is_none() { self.persistent = Some(Persistent::load_or_initialize(client)); } @@ -173,20 +170,18 @@ impl State { ) -> Result<&mut Persistent, Status> { Ok(self.load(client)?.persistent) } -} -#[derive(Debug, Eq, PartialEq)] -pub struct LoadedState<'t, const C: usize> { - pub runtime: &'t mut Runtime, - pub persistent: &'t mut Persistent, -} - -impl State { pub fn new() -> Self { Default::default() } } +#[derive(Debug, Eq, PartialEq)] +pub struct LoadedState<'t> { + pub runtime: &'t mut Runtime, + pub persistent: &'t mut Persistent, +} + #[derive(Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct Persistent { pub keys: Keys, @@ -206,7 +201,7 @@ pub struct Persistent { } #[derive(Clone, Debug, Default, Eq, PartialEq)] -pub struct Runtime { +pub struct Runtime { // aid: Option< // consecutive_pin_mismatches: u8, pub global_security_status: GlobalSecurityStatus, diff --git a/src/tlv.rs b/src/tlv.rs index 5d3ee33..7996401 100644 --- a/src/tlv.rs +++ b/src/tlv.rs @@ -3,6 +3,7 @@ //! Utilities for dealing with TLV (Tag-Length-Value) encoded data +#[allow(unused)] pub fn get_do<'input>(tag_path: &[u16], data: &'input [u8]) -> Option<&'input [u8]> { let mut to_ret = data; let mut remainder = data; diff --git a/src/vpicc.rs b/src/vpicc.rs index 9464e48..989a18d 100644 --- a/src/vpicc.rs +++ b/src/vpicc.rs @@ -10,7 +10,6 @@ use crate::Authenticator; const REQUEST_LEN: usize = 7609; const RESPONSE_LEN: usize = 7609; -const BUFFER_LEN: usize = 7609; /// Virtual PIV smartcard implementation. /// @@ -19,12 +18,12 @@ const BUFFER_LEN: usize = 7609; pub struct VirtualCard { request_buffer: RequestBuffer, response_buffer: ResponseBuffer, - card: Authenticator, BUFFER_LEN>, + card: Authenticator>, } impl VirtualCard { /// Creates a new virtual smart card from the given card. - pub fn new(card: Authenticator, BUFFER_LEN>) -> Self { + pub fn new(card: Authenticator>) -> Self { Self { request_buffer: Default::default(), response_buffer: Default::default(), diff --git a/tests/setup/mod.rs b/tests/setup/mod.rs index 45f8149..2a3537d 100644 --- a/tests/setup/mod.rs +++ b/tests/setup/mod.rs @@ -1,3 +1,4 @@ +#[allow(unused)] pub const COMMAND_SIZE: usize = 3072; #[macro_export] @@ -9,7 +10,7 @@ macro_rules! cmd { use trussed::virt::{Client, Ram}; -pub type Piv = piv_authenticator::Authenticator, COMMAND_SIZE>; +pub type Piv = piv_authenticator::Authenticator>; pub fn piv(test: impl FnOnce(&mut Piv) -> R) -> R { trussed::virt::with_ram_client("test", |client| {