From 8985ab051b6c5d4e591e5d6de6f5db856c8b0c02 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 23 Apr 2023 17:14:48 +0200 Subject: [PATCH] Use serialization helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- CHANGELOG.md | 6 ++++++ src/command/gen.rs | 9 ++++----- src/command/private_key_template.rs | 4 +--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ffe47d..2f0b5f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/command/gen.rs b/src/command/gen.rs index f64d825..9b563a0 100644 --- a/src/command/gen.rs +++ b/src/command/gen.rs @@ -301,11 +301,10 @@ fn read_rsa_key( 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)?; diff --git a/src/command/private_key_template.rs b/src/command/private_key_template.rs index a977b8c..4f344e5 100644 --- a/src/command/private_key_template.rs +++ b/src/command/private_key_template.rs @@ -208,14 +208,12 @@ fn put_rsa( ctx: LoadedContext<'_, R, T>, mechanism: Mechanism, ) -> Result, 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 })?;