mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Return NotFound when data object in not avalaible
This commit is contained in:
+31
-28
@@ -123,8 +123,8 @@ where
|
||||
Command::ChangeReference(change_reference) => {
|
||||
self.load()?.change_reference(change_reference)
|
||||
}
|
||||
Command::GetData(container) => self.get_data(container, reply),
|
||||
Command::PutData(put_data) => self.put_data(put_data),
|
||||
Command::GetData(container) => self.load()?.get_data(container, reply),
|
||||
Command::PutData(put_data) => self.load()?.put_data(put_data),
|
||||
Command::Select(_aid) => self.select(reply),
|
||||
Command::GeneralAuthenticate(authenticate) => {
|
||||
self.load()?
|
||||
@@ -203,32 +203,6 @@ where
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_data<const R: usize>(
|
||||
&mut self,
|
||||
container: Container,
|
||||
mut reply: Reply<'_, R>,
|
||||
) -> Result {
|
||||
// TODO: check security status, else return Status::SecurityStatusNotSatisfied
|
||||
|
||||
use state::ContainerStorage;
|
||||
reply.expand(&ContainerStorage(container).load(&mut self.trussed)?)
|
||||
}
|
||||
|
||||
fn put_data(&mut self, put_data: PutData<'_>) -> Result {
|
||||
// TODO: check security status, else return Status::SecurityStatusNotSatisfied
|
||||
|
||||
let (container, data) = match put_data {
|
||||
PutData::Any(container, data) => (container, data),
|
||||
PutData::BitGroupTemplate(data) => {
|
||||
(Container::BiometricInformationTemplatesGroupTemplate, data)
|
||||
}
|
||||
PutData::DiscoveryObject(data) => (Container::DiscoveryObject, data),
|
||||
};
|
||||
|
||||
use state::ContainerStorage;
|
||||
ContainerStorage(container).save(&mut self.trussed, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: trussed::Client + trussed::client::Ed255> LoadedAuthenticator<'a, T> {
|
||||
@@ -821,4 +795,33 @@ impl<'a, T: trussed::Client + trussed::client::Ed255> LoadedAuthenticator<'a, T>
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_data<const R: usize>(
|
||||
&mut self,
|
||||
container: Container,
|
||||
mut reply: Reply<'_, R>,
|
||||
) -> Result {
|
||||
// TODO: check security status, else return Status::SecurityStatusNotSatisfied
|
||||
|
||||
use state::ContainerStorage;
|
||||
match ContainerStorage(container).load(self.trussed)? {
|
||||
Some(data) => reply.expand(&data),
|
||||
None => Err(Status::NotFound),
|
||||
}
|
||||
}
|
||||
|
||||
fn put_data(&mut self, put_data: PutData<'_>) -> Result {
|
||||
// TODO: check security status, else return Status::SecurityStatusNotSatisfied
|
||||
|
||||
let (container, data) = match put_data {
|
||||
PutData::Any(container, data) => (container, data),
|
||||
PutData::BitGroupTemplate(data) => {
|
||||
(Container::BiometricInformationTemplatesGroupTemplate, data)
|
||||
}
|
||||
PutData::DiscoveryObject(data) => (Container::DiscoveryObject, data),
|
||||
};
|
||||
|
||||
use state::ContainerStorage;
|
||||
ContainerStorage(container).save(self.trussed, data)
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -546,16 +546,25 @@ impl ContainerStorage {
|
||||
})
|
||||
}
|
||||
|
||||
fn default(self) -> &'static [u8] {
|
||||
todo!()
|
||||
fn default(self) -> Option<Vec<u8, MAX_MESSAGE_LENGTH>> {
|
||||
match self.0 {
|
||||
Container::CardHolderUniqueIdentifier => panic!("CHUID should alway be set"),
|
||||
Container::CardCapabilityContainer => Some(
|
||||
crate::piv_types::CardCapabilityContainer::default()
|
||||
.to_heapless_vec()
|
||||
.unwrap(),
|
||||
),
|
||||
Container::DiscoveryObject => Some(Vec::from_slice(&DISCOVERY_OBJECT).unwrap()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load(
|
||||
self,
|
||||
client: &mut impl trussed::Client,
|
||||
) -> Result<Bytes<MAX_MESSAGE_LENGTH>, Status> {
|
||||
) -> Result<Option<Bytes<MAX_MESSAGE_LENGTH>>, Status> {
|
||||
load_if_exists(client, Location::Internal, &self.path())
|
||||
.map(|data| data.unwrap_or_else(|| Bytes::from_slice(self.default()).unwrap()))
|
||||
.map(|data| data.or_else(|| self.default().map(Bytes::from)))
|
||||
}
|
||||
|
||||
pub fn save(self, client: &mut impl trussed::Client, bytes: &[u8]) -> Result<(), Status> {
|
||||
|
||||
Reference in New Issue
Block a user