pv: Refactor 'get_verified_hkds'

Get rid of 'read_hkd' by refactoring the 'get_verified_hkds' function.
For this a new HkdLoader::load_and_verify is introduced that is a
reworked version of the original code.

In addition, add test cases for testing all the edge cases.

Assisted-by: IBM Bob:1.0.6
Signed-off-by: Marc Hartmayer <marc@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2026-07-28 18:05:38 +02:00
committed by Steffen Eiden
parent 1aa1558f91
commit 0263637d9f
10 changed files with 447 additions and 151 deletions
+4 -2
View File
@@ -6,10 +6,12 @@ use std::path::Path;
use anyhow::Result;
use log::{info, warn};
use pv::misc::{open_file, read_hkd};
use pv::misc::open_file;
use pv::request::NoVerifyHkd;
use pv::{FileAccessErrorType, PvCoreError};
use pvimg::error::{Error, OwnExitCode};
use pvimg::uvdata::{KeyExchangeTrait, SeHdr, UvKeyHashesV1};
use utils::hkd::{HkdLoader, HkdVersionSelection};
use utils::HexSlice;
use crate::cli::TestArgs;
@@ -72,7 +74,7 @@ where
let mut result = false;
for path in host_key_documents {
let hkd = read_hkd(path)?;
let hkd = HkdLoader::load_and_verify(path, &NoVerifyHkd, HkdVersionSelection::Auto)?;
if hdr.contains(hkd)? {
result = true;
log_println!(