MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / boot_option_bytes

Function boot_option_bytes

dstack-mr/src/uefi_var.rs:73–95  ·  view source on GitHub ↗

Build the raw bytes of a `Boot####` UEFI variable — the on-the-wire form of `EFI_LOAD_OPTION { Attributes, FilePathListLength, Description, FilePathList, OptionalData }`. The description is automatically NUL-terminated in UTF-16LE.

(
    attributes: u32,
    description: &str,
    file_path_nodes: &[DevicePathNode<'_>],
    optional_data: &[u8],
)

Source from the content-addressed store, hash-verified

71///
72/// The description is automatically NUL-terminated in UTF-16LE.
73pub fn boot_option_bytes(
74 attributes: u32,
75 description: &str,
76 file_path_nodes: &[DevicePathNode<'_>],
77 optional_data: &[u8],
78) -> Vec<u8> {
79 // Serialise the device-path list first so we know its length.
80 let mut file_path = Vec::new();
81 for node in file_path_nodes {
82 node.write_to(&mut file_path);
83 }
84
85 let mut desc = utf16_encode(description);
86 desc.extend_from_slice(&[0x00, 0x00]); // NUL terminator
87
88 let mut out = Vec::with_capacity(4 + 2 + desc.len() + file_path.len() + optional_data.len());
89 out.extend_from_slice(&attributes.to_le_bytes());
90 out.extend_from_slice(&(file_path.len() as u16).to_le_bytes());
91 out.extend_from_slice(&desc);
92 out.extend_from_slice(&file_path);
93 out.extend_from_slice(optional_data);
94 out
95}
96
97#[cfg(test)]
98mod tests {

Callers 2

rtmr0_logMethod · 0.85

Calls 3

utf16_encodeFunction · 0.85
write_toMethod · 0.80
lenMethod · 0.45

Tested by 1