mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Remove const generic in state
This commit is contained in:
committed by
Nicolas Stalder
parent
d5564b89be
commit
10dd4d929b
+1
-1
@@ -4,7 +4,7 @@ use apdu_dispatch::{app::App, command, response, Command};
|
||||
use trussed::client;
|
||||
|
||||
#[cfg(feature = "apdu-dispatch")]
|
||||
impl<T> App<{ command::SIZE }, { response::SIZE }> for Authenticator<T, { command::SIZE }>
|
||||
impl<T> App<{ command::SIZE }, { response::SIZE }> for Authenticator<T>
|
||||
where
|
||||
T: client::Client + client::Ed255 + client::Tdes,
|
||||
{
|
||||
|
||||
+8
-8
@@ -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<T, const C: usize> {
|
||||
state: state::State<C>,
|
||||
pub struct Authenticator<T> {
|
||||
state: state::State,
|
||||
trussed: T,
|
||||
}
|
||||
|
||||
impl<T, const C: usize> iso7816::App for Authenticator<T, C> {
|
||||
impl<T> iso7816::App for Authenticator<T> {
|
||||
fn aid(&self) -> iso7816::Aid {
|
||||
crate::constants::PIV_AID
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, const C: usize> Authenticator<T, C>
|
||||
impl<T> Authenticator<T>
|
||||
where
|
||||
T: client::Client + client::Ed255 + client::Tdes,
|
||||
{
|
||||
@@ -87,7 +87,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn respond<const R: usize>(
|
||||
pub fn respond<const R: usize, const C: usize>(
|
||||
&mut self,
|
||||
command: &iso7816::Command<C>,
|
||||
reply: &mut Data<R>,
|
||||
@@ -316,7 +316,7 @@ where
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn generate_asymmetric_keypair<const R: usize>(
|
||||
pub fn generate_asymmetric_keypair<const R: usize, const C: usize>(
|
||||
&mut self,
|
||||
command: &iso7816::Command<C>,
|
||||
reply: &mut Data<R>,
|
||||
@@ -453,7 +453,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn put_data(&mut self, command: &iso7816::Command<C>) -> Result {
|
||||
pub fn put_data<const C: usize>(&mut self, command: &iso7816::Command<C>) -> 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<const R: usize>(
|
||||
pub fn yubico_piv_extension<const R: usize, const C: usize>(
|
||||
&mut self,
|
||||
command: &iso7816::Command<C>,
|
||||
instruction: YubicoPivExtension,
|
||||
|
||||
+11
-16
@@ -148,16 +148,13 @@ pub struct Keys {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Eq, PartialEq)]
|
||||
pub struct State<const C: usize> {
|
||||
pub runtime: Runtime<C>,
|
||||
pub struct State {
|
||||
pub runtime: Runtime,
|
||||
pub persistent: Option<Persistent>,
|
||||
}
|
||||
|
||||
impl<const C: usize> State<C> {
|
||||
pub fn load(
|
||||
&mut self,
|
||||
client: &mut impl trussed::Client,
|
||||
) -> Result<LoadedState<'_, C>, Status> {
|
||||
impl State {
|
||||
pub fn load(&mut self, client: &mut impl trussed::Client) -> Result<LoadedState<'_>, Status> {
|
||||
if self.persistent.is_none() {
|
||||
self.persistent = Some(Persistent::load_or_initialize(client));
|
||||
}
|
||||
@@ -173,20 +170,18 @@ impl<const C: usize> State<C> {
|
||||
) -> 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<C>,
|
||||
pub persistent: &'t mut Persistent,
|
||||
}
|
||||
|
||||
impl<const C: usize> State<C> {
|
||||
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<const C: usize> {
|
||||
pub struct Runtime {
|
||||
// aid: Option<
|
||||
// consecutive_pin_mismatches: u8,
|
||||
pub global_security_status: GlobalSecurityStatus,
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-3
@@ -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<REQUEST_LEN>,
|
||||
response_buffer: ResponseBuffer<RESPONSE_LEN>,
|
||||
card: Authenticator<Client<Ram>, BUFFER_LEN>,
|
||||
card: Authenticator<Client<Ram>>,
|
||||
}
|
||||
|
||||
impl VirtualCard {
|
||||
/// Creates a new virtual smart card from the given card.
|
||||
pub fn new(card: Authenticator<Client<Ram>, BUFFER_LEN>) -> Self {
|
||||
pub fn new(card: Authenticator<Client<Ram>>) -> Self {
|
||||
Self {
|
||||
request_buffer: Default::default(),
|
||||
response_buffer: Default::default(),
|
||||
|
||||
+2
-1
@@ -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<Client<Ram>, COMMAND_SIZE>;
|
||||
pub type Piv = piv_authenticator::Authenticator<Client<Ram>>;
|
||||
|
||||
pub fn piv<R>(test: impl FnOnce(&mut Piv) -> R) -> R {
|
||||
trussed::virt::with_ram_client("test", |client| {
|
||||
|
||||
Reference in New Issue
Block a user