Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sign_count size #76

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/command/private_key_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CONCATENATION_KEY_DATA_DO: u16 = 0x5F48;

// § 4.4.3.12
pub fn put_private_key_template<const R: usize, T: trussed::Client>(
mut ctx: LoadedContext<'_, R, T>,
ctx: LoadedContext<'_, R, T>,
) -> Result<(), Status> {
let data = get_do(&[PRIVATE_KEY_TEMPLATE_DO], ctx.data).ok_or_else(|| {
warn!("Got put private key template without 4D DO");
Expand All @@ -26,16 +26,7 @@ pub fn put_private_key_template<const R: usize, T: trussed::Client>(
debug!("Importing {key_type:?} key");

match key_type {
KeyType::Sign => {
put_sign(ctx.lend())?;
ctx.state
.internal
.set_sign_count(0, ctx.backend.client_mut())
.map_err(|_err| {
warn!("Failed to save sign count: {_err}");
Status::UnspecifiedNonpersistentExecutionError
})?;
}
KeyType::Sign => put_sign(ctx)?,
KeyType::Dec => put_dec(ctx)?,
KeyType::Aut => put_aut(ctx)?,
}
Expand Down
18 changes: 6 additions & 12 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub struct Internal {
cardholder_name: Bytes<39>,
cardholder_sex: Sex,
language_preferences: Bytes<8>,
sign_count: usize,
sign_count: u32,
uif_sign: Uif,
uif_dec: Uif,
uif_aut: Uif,
Expand Down Expand Up @@ -615,19 +615,10 @@ impl Internal {
self.save(client)
}

pub fn sign_count(&self) -> usize {
pub fn sign_count(&self) -> u32 {
self.sign_count
}

pub fn set_sign_count(
&mut self,
count: usize,
client: &mut impl trussed::Client,
) -> Result<(), Error> {
self.sign_count = count;
self.save(client)
}

pub fn key_id(&self, ty: KeyType) -> Option<KeyId> {
match ty {
KeyType::Sign => self.signing_key,
Expand All @@ -654,7 +645,10 @@ impl Internal {
client: &mut impl trussed::Client,
) -> Result<Option<(KeyId, KeyOrigin)>, Error> {
match ty {
KeyType::Sign => swap(&mut self.signing_key, &mut new),
KeyType::Sign => {
self.sign_count = 0;
swap(&mut self.signing_key, &mut new)
}
KeyType::Dec => swap(&mut self.confidentiality_key, &mut new),
KeyType::Aut => swap(&mut self.aut_key, &mut new),
}
Expand Down