fix: pkg interpreting

This commit is contained in:
Didier Slof 2023-07-16 19:00:56 +02:00
parent 70a22810b2
commit 1ec1d5c9b2
Signed by: didier
GPG key ID: 01E71F18AA4398E5

View file

@ -9,28 +9,22 @@ impl TryFrom<Vec<u8>> for PKGFile {
fn try_from(value: Vec<u8>) -> Result<Self, ()> {
match value[0] {
1 => {
let header: Vec<u32> = value[..3]
.iter()
.map(|v| u32::from(*v))
.collect();
let header: Vec<u32> = value[..3].iter().map(|v| u32::from(*v)).collect();
let manifest_size: u32 = (header[1] << 8) | header[2];
if manifest_size > value.len() as u32 {
return Err(());
}
Ok(PKGFile {
manifest: match String::from_utf8(
value[
3..(manifest_size as usize + 3)
].to_vec()
)
{
value[3..(manifest_size as usize + 3)].to_vec(),
) {
Ok(s) => s,
_ => return Err(())
_ => return Err(()),
},
data: value[(manifest_size as usize + 3)..].to_vec(),
})
}
_ => Err(())
_ => Err(()),
}
}
}