Skip to content

Commit 3068e8d

Browse files
DGonzalezVillaltylerfanelli
authored andcommitted
Refactor: Chaning vlek_load api to thake in WrappedVlekHashstick
Since we're updating the major version, I'd prefer having users pass the UAPI structure to the API instead of a slice. By using the UAPI struct, the library can perform the appropriate length and reserved field checks before passing the data to the firmware. This gives us better validation of the data upfront. This approach is cleaner than passing a raw slice and makes it easier to work with compared to manually managing arrays or buffers. Signed-off-by: DGonzalezVillal <Diego.GonzalezVillalobos@amd.com>
1 parent f6769b4 commit 3068e8d

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/firmware/host/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,26 @@ impl Firmware {
289289
///
290290
/// let mut firmware: Firmware = Firmware::open().unwrap();
291291
///
292-
/// // (Optional), Parse the bytes into a `WrappedVlekHashstick` to verify content before passing to the firmware.:
292+
/// // Parse the bytes into a `WrappedVlekHashstick` to verify content before passing to the firmware.:
293293
/// let generation = Generation::identify_host_generation()?;
294294
/// let hashstick = WrappedVlekHashstick::from_bytes(hashstick_bytes.as_slice(), generation)?;
295295
///
296-
/// // Parse back into bytes
297-
/// let mut buffer: [u8; 432] = [0; 432];
298-
/// hashstick.write_bytes(&mut buffer[..], generation)?;
299-
///
300296
/// // Load the VLEK Hashstick into the AMD Secure Processor.
301-
/// firmware.snp_vlek_load(buffer.as_slice()).unwrap();
297+
/// firmware.snp_vlek_load(hashstick).unwrap();
302298
/// ```
303-
pub fn snp_vlek_load(&mut self, hashstick_bytes: &[u8]) -> Result<(), UserApiError> {
299+
pub fn snp_vlek_load(&mut self, hashstick: WrappedVlekHashstick) -> Result<(), UserApiError> {
304300
use std::convert::TryFrom;
305301

306302
use types::FFI::types::{SnpVlekLoad, WrappedVlekHashstick as FFIWrappedVlekHashstick};
307303

304+
let generation = Generation::identify_host_generation()?;
305+
306+
let mut buffer: [u8; 432] = [0; 432];
307+
308+
hashstick.write_bytes(&mut buffer[..], generation)?;
309+
308310
let parsed_bytes: FFIWrappedVlekHashstick =
309-
FFIWrappedVlekHashstick::try_from(hashstick_bytes)?;
311+
FFIWrappedVlekHashstick::try_from(buffer.as_slice())?;
310312

311313
let mut vlek_load: SnpVlekLoad = SnpVlekLoad::new(&parsed_bytes);
312314
let mut cmd_buf = Command::from_mut(&mut vlek_load);

0 commit comments

Comments
 (0)