From 175ef9ab1ae99b126f2feee6cd63c0152a35bc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 21 Feb 2023 17:04:55 +0100 Subject: [PATCH] Workaround cbor-smol bug --- src/backend/data.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/backend/data.rs b/src/backend/data.rs index 1ce1677..29ed36b 100644 --- a/src/backend/data.rs +++ b/src/backend/data.rs @@ -29,9 +29,15 @@ pub(crate) type Hash = ByteArray; pub(crate) type ChaChaTag = ByteArray; pub(crate) type Key = ByteArray; +#[derive(Debug, Deserialize, Serialize)] +struct WrappedKeyData { + wrapped_key: Key, + tag: ChaChaTag, +} + #[derive(Debug, Deserialize, Serialize)] enum KeyOrHash { - Key { wrapped_key: Key, tag: ChaChaTag }, + Key(WrappedKeyData), Hash(Hash), } @@ -75,10 +81,10 @@ impl PinData { .expect("Wrapping the key should always work, length are acceptable") .into(); - KeyOrHash::Key { + KeyOrHash::Key(WrappedKeyData { wrapped_key: key, tag: tag.into(), - } + }) }) .unwrap_or_else(|| KeyOrHash::Hash(hash(id, pin, &salt))); Self { @@ -177,7 +183,7 @@ impl<'a> PinDataMut<'a> { CheckResult::Failed } } - KeyOrHash::Key { wrapped_key, tag } => { + KeyOrHash::Key(WrappedKeyData { wrapped_key, tag }) => { let app_key = application_key()?; if let Some(k) = self.unwrap_key(pin, &app_key, wrapped_key, &tag) { CheckResult::Derived { k, app_key } @@ -284,10 +290,10 @@ impl<'a> PinDataMut<'a> { id: self.id, retries: self.retries, salt, - data: KeyOrHash::Key { + data: KeyOrHash::Key(WrappedKeyData { wrapped_key: old_key, tag: tag.into(), - }, + }), }; }