Skip to content

Commit

Permalink
Merge pull request #117 from Nitrokey/external-storage
Browse files Browse the repository at this point in the history
Use external storage
  • Loading branch information
sosthene-nitrokey committed Feb 10, 2023
2 parents e556055 + d7c33d7 commit ae13648
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 285 deletions.
13 changes: 11 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use core::fmt::Debug;

use trussed::try_syscall;
use trussed::types::Location;

use crate::command::Password;
use crate::error::Error;
Expand Down Expand Up @@ -41,8 +42,16 @@ impl<T: trussed::Client> Backend<T> {
}

/// Checks whether the given value matches the pin of the given type.
pub fn verify_pin(&mut self, pin: Password, value: &[u8], state: &mut state::Internal) -> bool {
state.verify_pin(&mut self.client, value, pin).is_ok()
pub fn verify_pin(
&mut self,
storage: Location,
pin: Password,
value: &[u8],
state: &mut state::Persistent,
) -> bool {
state
.verify_pin(&mut self.client, storage, value, pin)
.is_ok()
}

/// Ask for confirmation of presence from the user with a default timeout of 15 seconds
Expand Down
8 changes: 6 additions & 2 deletions src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use hex_literal::hex;
use iso7816::Status;
use trussed::types::Location;

pub(crate) mod reply;

Expand Down Expand Up @@ -116,6 +117,8 @@ pub struct Options {

/// Does the card have a button for user input?
pub button_available: bool,
/// Which trussed storage to use
pub storage: Location,
}

impl Options {
Expand Down Expand Up @@ -153,6 +156,7 @@ impl Default for Options {
// TODO: Copied from Nitrokey Pro
historical_bytes: heapless::Vec::from_slice(&hex!("0031F573C00160009000")).unwrap(),
button_available: true,
storage: Location::External,
}
}
}
Expand All @@ -171,7 +175,7 @@ impl<'a, const R: usize, T: trussed::Client> Context<'a, R, T> {
Ok(LoadedContext {
state: self
.state
.load(self.backend.client_mut())
.load(self.backend.client_mut(), self.options.storage)
.map_err(|_| Status::UnspecifiedNonpersistentExecutionError)?,
options: self.options,
backend: self.backend,
Expand All @@ -196,7 +200,7 @@ impl<'a, const R: usize, T: trussed::Client> Context<'a, R, T> {
}

#[derive(Debug)]
/// Context with the internal state loaded from flash
/// Context with the persistent state loaded from flash
pub struct LoadedContext<'a, const R: usize, T: trussed::Client> {
pub backend: &'a mut Backend<T>,
pub options: &'a Options,
Expand Down
Loading

0 comments on commit ae13648

Please sign in to comment.