init: initial commit of packager

This commit is contained in:
Strix 2023-10-14 22:39:39 +02:00
commit 36c782a564
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
25 changed files with 478 additions and 0 deletions

36
pkgfile/src/lib.rs Normal file
View file

@ -0,0 +1,36 @@
pub struct PKGFile {
pub manifest: String,
pub data: Vec<u8>,
}
impl TryFrom<Vec<u8>> for PKGFile {
type Error = ();
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 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)
].to_vec()
)
{
Ok(s) => s,
_ => return Err(())
},
data: value[(manifest_size as usize)..].to_vec(),
})
}
_ => Err(())
}
}
}