mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Remove the need for const generics in the respond implementations
This commit is contained in:
committed by
Nicolas Stalder
parent
82b2898d1d
commit
bf7b72d320
+2
-24
@@ -55,7 +55,7 @@ pub enum Command<'l> {
|
||||
GeneralAuthenticate(GeneralAuthenticate),
|
||||
/// Store a data object / container.
|
||||
PutData(PutData),
|
||||
GenerateAsymmetric(GenerateAsymmetric),
|
||||
GenerateAsymmetric(GenerateAsymmetricKeyReference),
|
||||
|
||||
/* Yubico commands */
|
||||
YkExtension(YubicoPivExtension),
|
||||
@@ -252,22 +252,6 @@ impl TryFrom<&[u8]> for PutData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct GenerateAsymmetricArguments<'l> {
|
||||
pub key_reference: GenerateAsymmetricKeyReference,
|
||||
pub data: &'l [u8],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum GenerateAsymmetric {}
|
||||
|
||||
impl TryFrom<GenerateAsymmetricArguments<'_>> for GenerateAsymmetric {
|
||||
type Error = Status;
|
||||
fn try_from(_arguments: GenerateAsymmetricArguments<'_>) -> Result<Self, Self::Error> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
|
||||
type Error = Status;
|
||||
/// The first layer of unraveling the iso7816::Command onion.
|
||||
@@ -340,13 +324,7 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
|
||||
}
|
||||
|
||||
(0x00, Instruction::GenerateAsymmetricKeyPair, 0x00, p2) => {
|
||||
let key_reference = GenerateAsymmetricKeyReference::try_from(p2)?;
|
||||
Self::GenerateAsymmetric(GenerateAsymmetric::try_from(
|
||||
GenerateAsymmetricArguments {
|
||||
key_reference,
|
||||
data,
|
||||
},
|
||||
)?)
|
||||
Self::GenerateAsymmetric(GenerateAsymmetricKeyReference::try_from(p2)?)
|
||||
}
|
||||
// (0x00, 0x01, 0x10, 0x00)
|
||||
(0x00, Instruction::Unknown(0x01), 0x00, 0x00) => {
|
||||
|
||||
+4
-16
@@ -319,22 +319,13 @@ where
|
||||
|
||||
pub fn generate_asymmetric_keypair<const R: usize, const C: usize>(
|
||||
&mut self,
|
||||
command: &iso7816::Command<C>,
|
||||
data: &[u8],
|
||||
reply: &mut Data<R>,
|
||||
) -> Result {
|
||||
if !self.state.runtime.app_security_status.management_verified {
|
||||
return Err(Status::SecurityStatusNotSatisfied);
|
||||
}
|
||||
|
||||
if command.p1 != 0x00 {
|
||||
return Err(Status::IncorrectP1OrP2Parameter);
|
||||
}
|
||||
|
||||
if command.p2 != 0x9a {
|
||||
// TODO: make more general
|
||||
return Err(Status::FunctionNotSupported);
|
||||
}
|
||||
|
||||
// example: 00 47 00 9A 0B
|
||||
// AC 09
|
||||
// # P256
|
||||
@@ -357,7 +348,7 @@ where
|
||||
// }
|
||||
|
||||
// TODO: iterate on this, don't expect tags..
|
||||
let input = derp::Input::from(command.data());
|
||||
let input = derp::Input::from(data);
|
||||
// let (mechanism, parameter) = input.read_all(derp::Error::Read, |input| {
|
||||
let (mechanism, _pin_policy, _touch_policy) = input
|
||||
.read_all(derp::Error::Read, |input| {
|
||||
@@ -454,11 +445,8 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn put_data<const C: usize>(&mut self, command: &iso7816::Command<C>) -> Result {
|
||||
pub fn put_data(&mut self, data: &[u8]) -> Result {
|
||||
info!("PutData");
|
||||
if command.p1 != 0x3f || command.p2 != 0xff {
|
||||
return Err(Status::IncorrectP1OrP2Parameter);
|
||||
}
|
||||
|
||||
// if !self.state.runtime.app_security_status.management_verified {
|
||||
// return Err(Status::SecurityStatusNotSatisfied);
|
||||
@@ -474,7 +462,7 @@ where
|
||||
// 88 1A 89 18 AA 81 D5 48 A5 EC 26 01 60 BA 06 F6 EC 3B B6 05 00 2E B6 3D 4B 28 7F 86
|
||||
//
|
||||
|
||||
let input = derp::Input::from(command.data());
|
||||
let input = derp::Input::from(data);
|
||||
let (data_object, data) = input
|
||||
.read_all(derp::Error::Read, |input| {
|
||||
let data_object = derp::expect_tag_and_get_value(input, 0x5c)?;
|
||||
|
||||
Reference in New Issue
Block a user