From fdea2863fab1f96197abc0627a2e082de7be0e30 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sat, 29 Apr 2023 15:58:21 +0000 Subject: [PATCH] Persistence bugfixing --- matter/src/crypto/mod.rs | 4 +++- matter/src/tlv/traits.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/matter/src/crypto/mod.rs b/matter/src/crypto/mod.rs index 27ba187..3b7b4c4 100644 --- a/matter/src/crypto/mod.rs +++ b/matter/src/crypto/mod.rs @@ -100,7 +100,9 @@ impl ToTLV for KeyPair { tw.str16(TagType::Anonymous, &buf[..size])?; let size = self.get_private_key(&mut buf)?; - tw.str16(TagType::Anonymous, &buf[..size]) + tw.str16(TagType::Anonymous, &buf[..size])?; + + tw.end_container() } } diff --git a/matter/src/tlv/traits.rs b/matter/src/tlv/traits.rs index 100eb07..0311cb3 100644 --- a/matter/src/tlv/traits.rs +++ b/matter/src/tlv/traits.rs @@ -35,7 +35,7 @@ pub trait FromTLV<'a> { } } -impl<'a, T: FromTLV<'a>, const N: usize> FromTLV<'a> for [T; N] { +impl<'a, T: FromTLV<'a> + Default, const N: usize> FromTLV<'a> for [T; N] { fn from_tlv(t: &TLVElement<'a>) -> Result where Self: Sized, @@ -49,6 +49,13 @@ impl<'a, T: FromTLV<'a>, const N: usize> FromTLV<'a> for [T; N] { } } + // TODO: This was the old behavior before rebasing the + // implementation on top of heapless::Vec (to avoid requiring Copy) + // Not sure why we actually need that yet, but without it unit tests fail + while a.len() < N { + a.push(Default::default()).map_err(|_| Error::NoSpace)?; + } + a.into_array().map_err(|_| Error::Invalid) } }