From 2739b8a488fbb652b81bf3af6679bdde870bb2d4 Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Mon, 7 Jul 2025 15:47:04 +0200 Subject: [PATCH] pv/examples: Add example for calculating host-key hashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Jan Höppner Signed-off-by: Steffen Eiden Signed-off-by: Jan Höppner --- rust/pv/examples/hash_hkd/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 rust/pv/examples/hash_hkd/main.rs diff --git a/rust/pv/examples/hash_hkd/main.rs b/rust/pv/examples/hash_hkd/main.rs new file mode 100644 index 00000000..49dcd9e4 --- /dev/null +++ b/rust/pv/examples/hash_hkd/main.rs @@ -0,0 +1,28 @@ +#![allow(missing_docs)] + +use pv::request::EcPubKeyCoord; +use pv_core::misc::encode_hex; +use s390_pv as pv; + +use std::env::args; + +use pv::misc::{read_certs, read_file}; +use pv::{Error, Result}; + +fn main() -> Result<()> { + let hkd = args().nth(1).expect("Expect one Host-key document"); + let hkd_bin = read_file(&hkd, "Host-key document")?; + let certs = read_certs(hkd_bin).map_err(|source| Error::HkdNotPemOrDer { hkd, source })?; + let hkd_cert = certs + .first() + .expect("Expect at least one certificate in the HKD file"); + + let pc: EcPubKeyCoord = hkd_cert + .public_key() + .expect("Expected a public key in the Host-key document") + .try_into() + .unwrap(); + + println!("{}", encode_hex(pc.sha256().unwrap())); + Ok(()) +}