Skip to main content

efivar_fix/
reader.rs

1use crate::Error;
2
3use super::efi::{Variable, VariableFlags};
4
5/// Represents the capability of reading EFI variables
6pub trait VarReader {
7    /// Read the EFI variable `name` and return its attributes and raw value
8    ///
9    /// The caller is responsible for allocating a large enough buffer to hold
10    /// the value for the target variable. This interface is used since some backends
11    /// (Windows) don't have an API for reporting the value size before reading it.
12    ///
13    /// # Arguments
14    ///
15    /// * `var`: variable to read
16    /// * `value`: target buffer for returning the variable value
17    ///
18    /// # Return value
19    ///
20    /// On success, number of bytes read and associated EFI variable flags.
21    fn read(&self, var: &Variable) -> crate::Result<(Vec<u8>, VariableFlags)>;
22    fn exists(&self, var: &Variable) -> crate::Result<bool> {
23        match self.read(var) {
24            Ok(_) => Ok(true),
25            Err(Error::VarNotFound { var: _ }) => Ok(false),
26            Err(err) => Err(err),
27        }
28    }
29}