Skip to content

Commit

Permalink
Use serialization helpers
Browse files Browse the repository at this point in the history
Instead of using Trussed’s re-exports of postcard that will be removed
in Trussed 0.2.0, we use the public and stable serialization helper
methods.
  • Loading branch information
robin-nitrokey committed Apr 24, 2023
1 parent 2e09631 commit bdd1d16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ SPDX-License-Identifier: CC0-1.0

# Changelog

## Unreleased

## Changes

- Use stable serialization helpers instead of postcard directly.

## [v0.4.0][] (2023-02-24)

### Features
Expand Down
9 changes: 4 additions & 5 deletions src/command/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@ fn read_rsa_key<const R: usize, T: trussed::Client + AuthClient>(
Status::UnspecifiedNonpersistentExecutionError
})?
.serialized_key;
let parsed_pubkey_data: RsaPublicParts =
trussed::postcard_deserialize(&pubkey_data).map_err(|_err| {
error!("Failed to deserialize public key");
Status::UnspecifiedNonpersistentExecutionError
})?;
let parsed_pubkey_data = RsaPublicParts::deserialize(&pubkey_data).map_err(|_err| {
error!("Failed to deserialize public key");
Status::UnspecifiedNonpersistentExecutionError
})?;
ctx.reply.expand(&[0x81])?;
ctx.reply.append_len(parsed_pubkey_data.n.len())?;
ctx.reply.expand(parsed_pubkey_data.n)?;
Expand Down
4 changes: 1 addition & 3 deletions src/command/private_key_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,12 @@ fn put_rsa<const R: usize, T: trussed::Client + AuthClient>(
ctx: LoadedContext<'_, R, T>,
mechanism: Mechanism,
) -> Result<Option<(KeyId, KeyId)>, Status> {
use trussed::{postcard_serialize_bytes, types::SerializedKey};

let key_data = parse_rsa_template(ctx.data).ok_or_else(|| {
warn!("Unable to parse RSA key");
Status::IncorrectDataParameter
})?;

let key_message: SerializedKey = postcard_serialize_bytes(&key_data).map_err(|_err| {
let key_message = key_data.serialize().map_err(|_err| {
error!("Failed to serialize RSA key: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
})?;
Expand Down

0 comments on commit bdd1d16

Please sign in to comment.