fix: pkg interpreting
This commit is contained in:
parent
174bbe93ec
commit
ba3e75c3fb
1 changed files with 6 additions and 12 deletions
|
@ -9,28 +9,22 @@ impl TryFrom<Vec<u8>> for PKGFile {
|
||||||
fn try_from(value: Vec<u8>) -> Result<Self, ()> {
|
fn try_from(value: Vec<u8>) -> Result<Self, ()> {
|
||||||
match value[0] {
|
match value[0] {
|
||||||
1 => {
|
1 => {
|
||||||
let header: Vec<u32> = value[..3]
|
let header: Vec<u32> = value[..3].iter().map(|v| u32::from(*v)).collect();
|
||||||
.iter()
|
|
||||||
.map(|v| u32::from(*v))
|
|
||||||
.collect();
|
|
||||||
let manifest_size: u32 = (header[1] << 8) | header[2];
|
let manifest_size: u32 = (header[1] << 8) | header[2];
|
||||||
if manifest_size > value.len() as u32 {
|
if manifest_size > value.len() as u32 {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
Ok(PKGFile {
|
Ok(PKGFile {
|
||||||
manifest: match String::from_utf8(
|
manifest: match String::from_utf8(
|
||||||
value[
|
value[3..(manifest_size as usize + 3)].to_vec(),
|
||||||
3..(manifest_size as usize + 3)
|
) {
|
||||||
].to_vec()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
_ => return Err(())
|
_ => return Err(()),
|
||||||
},
|
},
|
||||||
data: value[(manifest_size as usize + 3)..].to_vec(),
|
data: value[(manifest_size as usize + 3)..].to_vec(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => Err(())
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue