Skip to content

Instantly share code, notes, and snippets.

@SamYaple
Last active May 19, 2022 17:47
Show Gist options
  • Save SamYaple/34007699d0f0286c072b2556334d5a3a to your computer and use it in GitHub Desktop.
Save SamYaple/34007699d0f0286c072b2556334d5a3a to your computer and use it in GitHub Desktop.
fn parse_hex_hash(s: &str) -> nom::IResult<&str, apt::Hash> {
let (s, bytes) = many0(parse_hex_byte)(s)?;
let hash = match bytes.len() {
16 => {
let mut md5 = [0u8; 16];
md5.copy_from_slice(&bytes[..16]);
apt::Hash::md5(md5)
}
20 => {
let mut sha1 = [0u8; 20];
sha1.copy_from_slice(&bytes[..20]);
apt::Hash::sha1(sha1)
}
32 => {
let mut sha256 = [0u8; 32];
sha256.copy_from_slice(&bytes[..32]);
apt::Hash::sha256(sha256)
}
64 => {
let mut sha512 = [0u8; 64];
sha512.copy_from_slice(&bytes[..64]);
apt::Hash::sha512(sha512)
}
_ => panic!(),
};
Ok((s, hash))
}
//pub mod package;
pub mod release;
#[allow(non_camel_case_types)]
#[derive(PartialEq)]
pub enum Compression {
none(usize),
bz2(usize),
gz(usize),
xz(usize),
}
#[allow(non_camel_case_types)]
#[derive(PartialEq)]
pub enum Arch {
aarch64,
amd64,
arm64,
armhf,
i386,
ppc64el,
riscv64,
s390x,
}
#[allow(non_camel_case_types)]
#[derive(PartialEq)]
pub enum Hash {
md5([u8; 16]),
sha1([u8; 20]),
sha256([u8; 32]),
sha512([u8; 64]),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment