From c145a451ef119581db78341bcca730047890ebce Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 24 Oct 2024 19:35:24 +0200 Subject: [PATCH] Remove cbor_serialize_message helper The cbor_serialize_message helper mixed re-exports of cbor-smol from trussed and ctap-types. This can be problematic if both select different versions. It could be fixed by keeping both in sync, but to avoid this problem entirely, we can also just use cbor_serialize_bytes from Trussed directly. --- src/ctap2/pin.rs | 6 +++--- src/lib.rs | 12 +----------- src/state.rs | 4 ++-- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/ctap2/pin.rs b/src/ctap2/pin.rs index 61b896b..2fb893a 100644 --- a/src/ctap2/pin.rs +++ b/src/ctap2/pin.rs @@ -1,8 +1,8 @@ -use crate::{cbor_serialize_message, TrussedRequirements}; +use crate::TrussedRequirements; use cosey::EcdhEsHkdf256PublicKey; use ctap_types::{ctap2::client_pin::Permissions, Error, Result}; use trussed::{ - cbor_deserialize, + cbor_deserialize, cbor_serialize_bytes, client::{CryptoClient, HmacSha256, P256}, syscall, try_syscall, types::{ @@ -312,7 +312,7 @@ impl<'a, T: TrussedRequirements> PinProtocol<'a, T> { } fn shared_secret_impl(&mut self, peer_key: &EcdhEsHkdf256PublicKey) -> Option { - let serialized_peer_key = cbor_serialize_message(peer_key).ok()?; + let serialized_peer_key: Message = cbor_serialize_bytes(peer_key).ok()?; let peer_key = try_syscall!(self.trussed.deserialize_p256_key( &serialized_peer_key, KeySerialization::EcdhEsHkdf256, diff --git a/src/lib.rs b/src/lib.rs index 8f2cc86..ce9d949 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,11 +20,7 @@ generate_macros!(); use core::time::Duration; -use trussed::{ - client, syscall, - types::{Location, Message}, - Client as TrussedClient, -}; +use trussed::{client, syscall, types::Location, Client as TrussedClient}; use trussed_fs_info::{FsInfoClient, FsInfoReply}; use trussed_hkdf::HkdfClient; @@ -252,12 +248,6 @@ impl UserPresence for Conforming { } } -fn cbor_serialize_message( - object: &T, -) -> core::result::Result { - trussed::cbor_serialize_bytes(object) -} - impl Authenticator where UP: UserPresence, diff --git a/src/state.rs b/src/state.rs index eeab456..38c4095 100644 --- a/src/state.rs +++ b/src/state.rs @@ -11,7 +11,7 @@ use ctap_types::{ }; use littlefs2_core::path; use trussed::{ - client, syscall, try_syscall, + cbor_serialize_bytes, client, syscall, try_syscall, types::{KeyId, Location, Mechanism, Path, PathBuf}, Client as TrussedClient, }; @@ -299,7 +299,7 @@ impl PersistentState { } pub fn save(&self, trussed: &mut T) -> Result<()> { - let data = crate::cbor_serialize_message(self).unwrap(); + let data = cbor_serialize_bytes(self).unwrap(); syscall!(trussed.write_file( Location::Internal,