Persistence bugfixing

This commit is contained in:
ivmarkov 2023-04-29 15:58:21 +00:00
parent 86e01a0a1b
commit 934ecb9165
2 changed files with 11 additions and 2 deletions

View file

@ -100,7 +100,9 @@ impl ToTLV for KeyPair {
tw.str16(TagType::Anonymous, &buf[..size])?; tw.str16(TagType::Anonymous, &buf[..size])?;
let size = self.get_private_key(&mut buf)?; let size = self.get_private_key(&mut buf)?;
tw.str16(TagType::Anonymous, &buf[..size]) tw.str16(TagType::Anonymous, &buf[..size])?;
tw.end_container()
} }
} }

View file

@ -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<Self, Error> fn from_tlv(t: &TLVElement<'a>) -> Result<Self, Error>
where where
Self: Sized, 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) a.into_array().map_err(|_| Error::Invalid)
} }
} }