linux_bootloader/
unified_sections.rs

1/// List of PE sections that have a special meaning with respect to
2/// UKI specification.
3/// This is the canonical order in which they are measured into TPM
4/// PCR 11.
5/// !!! DO NOT REORDER !!!
6#[repr(u8)]
7pub enum UnifiedSection {
8    Linux = 0,
9    OsRel = 1,
10    CmdLine = 2,
11    Initrd = 3,
12    Splash = 4,
13    Dtb = 5,
14    PcrSig = 6,
15    PcrPkey = 7,
16}
17
18impl TryFrom<&str> for UnifiedSection {
19    type Error = uefi::Error;
20    fn try_from(value: &str) -> Result<Self, Self::Error> {
21        Ok(match value {
22            ".linux" => Self::Linux,
23            ".osrel" => Self::OsRel,
24            ".cmdline" => Self::CmdLine,
25            ".initrd" => Self::Initrd,
26            ".splash" => Self::Splash,
27            ".dtb" => Self::Dtb,
28            ".pcrsig" => Self::PcrSig,
29            ".pcrpkey" => Self::PcrPkey,
30            _ => return Err(uefi::Status::INVALID_PARAMETER.into()),
31        })
32    }
33}
34
35impl UnifiedSection {
36    /// Whether this section should be measured into TPM.
37    pub fn should_be_measured(&self) -> bool {
38        !matches!(self, UnifiedSection::PcrSig)
39    }
40}