From 3a9a7ebf025722a0265ca45166a4e9c5bd3e9bf7 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 Sep 2024 17:01:13 +0800 Subject: [PATCH] length of a record stored is the `pos` field for rkyv-to-pddb prior use of `rkyv` reserves two bytes to record `pos` pre-pended to the rkyv record the new rkyv works without having to do that because it indexes the rkyv data off the end of the stored records. Thus, all you need to know is the total length of the byte slice that stores the serialized data. This is available as the return argument when you read a PDDB key, so we don't have to explicitly store it anymore. --- libs/tls/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/tls/src/lib.rs b/libs/tls/src/lib.rs index a6febe522..357aa3708 100644 --- a/libs/tls/src/lib.rs +++ b/libs/tls/src/lib.rs @@ -13,7 +13,7 @@ use modals::Modals; use ota::{ArchivedOwnedTrustAnchor, OwnedTrustAnchor}; use rustls::pki_types::{CertificateDer, TrustAnchor}; use rustls::{ClientConfig, ClientConnection, RootCertStore}; -use x509_parser::prelude::{parse_x509_certificate, FromDer, X509Certificate}; +use x509_parser::prelude::{FromDer, X509Certificate, parse_x509_certificate}; use xous_names::XousNames; /// PDDB Dict for tls trusted certificates keys @@ -165,8 +165,9 @@ impl Tls { Ok(mut pddb_key) => { let mut bytes = [0u8; ota::MAX_OTA_BYTES]; match pddb_key.read(&mut bytes) { - Ok(_) => { - let ata = unsafe { rkyv::access_unchecked::(&bytes[..]) }; + Ok(pos) => { + let ata = + unsafe { rkyv::access_unchecked::(&bytes[..pos]) }; let ta = rkyv::deserialize::(ata).ok(); log::info!("get trust anchor {}", key); log::trace!("get trust anchor'{}' = '{:?}'", key, &ta);