pv: Change ec_key() to return Option<&PKeyRef<Public>>

Prepare the API for future host keys that might not have an EC key by
returning Option instead of a direct reference. Additionally, use
&PKeyRef<Public> as the borrowed view on PKey for better API
consistency.

Signed-off-by: Marc Hartmayer <marc@linux.ibm.com>
Reviewed-by: Timo Keller <tkeller@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-07 11:36:49 +02:00
committed by Steffen Eiden
parent 91123e5d45
commit 1746d2bb6a

View File

@@ -4,7 +4,7 @@
//! Host key types for UV requests
use openssl::pkey::{PKey, Public};
use openssl::pkey::{PKey, PKeyRef, Public};
/// Versioned host keys container
#[non_exhaustive]
@@ -16,10 +16,10 @@ pub enum HostKey {
impl HostKey {
/// Return the ECDH public key
pub fn ec_key(&self) -> &PKey<Public> {
match self {
pub fn ec_key(&self) -> Option<&PKeyRef<Public>> {
Some(match self {
HostKey::V1(ec_key) => ec_key,
}
})
}
}