mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Use correct length in advance when loading files
This reduces the need to shuffle the stack
This commit is contained in:
+5
-3
@@ -907,9 +907,12 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent
|
||||
_ => &[0x53],
|
||||
};
|
||||
reply.expand(tag)?;
|
||||
let offset = reply.len();
|
||||
match container {
|
||||
Container::KeyHistoryObject => self.get_key_history_object(reply.lend())?,
|
||||
Container::KeyHistoryObject => {
|
||||
let offset = reply.len();
|
||||
self.get_key_history_object(reply.lend())?;
|
||||
reply.prepend_len(offset)?;
|
||||
}
|
||||
_ => {
|
||||
if !ContainerStorage(container).load(
|
||||
self.trussed,
|
||||
@@ -920,7 +923,6 @@ impl<'a, T: trussed::Client + AuthClient + trussed::client::Ed255> LoadedAuthent
|
||||
}
|
||||
}
|
||||
}
|
||||
reply.prepend_len(offset)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -632,6 +632,7 @@ fn load_if_exists_streaming<const R: usize>(
|
||||
Ok(r) => {
|
||||
read_len += r.data.len();
|
||||
file_len = r.len;
|
||||
buffer.append_len(file_len)?;
|
||||
buffer.expand(&r.data)?;
|
||||
}
|
||||
Err(_) => match try_syscall!(client.entry_metadata(location, path.clone())) {
|
||||
@@ -752,6 +753,7 @@ impl ContainerStorage {
|
||||
}
|
||||
}
|
||||
|
||||
// Write the length of the file and write
|
||||
pub fn load<const R: usize>(
|
||||
self,
|
||||
client: &mut impl trussed::Client,
|
||||
@@ -763,6 +765,7 @@ impl ContainerStorage {
|
||||
}
|
||||
|
||||
if let Some(data) = self.default() {
|
||||
reply.append_len(data.len())?;
|
||||
reply.expand(&data)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user