cross_authenticode/
win_certificate.rs

1#![allow(dead_code)]
2use crate::error::AuthenticodeError;
3
4#[derive(Debug)]
5pub struct WinCertificate<'a> {
6    pub length: u32,
7    pub revision: u16,
8    pub certificate_type: u16,
9    pub certificate: &'a [u8],
10}
11
12impl<'a> WinCertificate<'a> {
13    pub fn new(data: &'a [u8], offset: u32) -> Result<Self, AuthenticodeError> {
14        let offset = offset as usize;
15        let length = u32::from_le_bytes(data[offset..offset + 4].try_into()?);
16        let revision = u16::from_le_bytes(data[offset + 4..offset + 6].try_into()?);
17        let certificate_type = u16::from_le_bytes(data[offset + 6..offset + 8].try_into()?);
18        let certificate = &data[offset + 8..(offset + length as usize)];
19
20        Ok(Self {
21            length,
22            revision,
23            certificate_type,
24            certificate,
25        })
26    }
27}