Skip to content

Commit

Permalink
Use postcard directly
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, either use the public wrapper provided by Trussed or
postcard directly.
  • Loading branch information
robin-nitrokey committed Apr 23, 2023
1 parent 2e09631 commit 42358c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ subtle = { version = "2.4.1", default-features = false }
trussed = "0.1.0"
trussed-rsa-alloc = { version = "0.1.0", optional = true }
serde_repr = "0.1"
postcard = "0.7.0"
hex-literal = "0.3.4"
trussed-auth = "0.2.1"

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
13 changes: 8 additions & 5 deletions src/command/private_key_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,20 @@ 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};
use trussed::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| {
error!("Failed to serialize RSA key: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
})?;
// TODO: move serialization into trussed
let key_message = postcard::to_vec(&key_data)
.map(SerializedKey::from)
.map_err(|_err| {
error!("Failed to serialize RSA key: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
})?;
let key = try_syscall!(ctx.backend.client_mut().unsafe_inject_key(
mechanism,
&key_message,
Expand Down

0 comments on commit 42358c3

Please sign in to comment.