From 89f475cee1485a20db2b910bf44406232039473e Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 14 Oct 2024 12:18:54 +0000 Subject: [PATCH] pv/req: Move constant out of function definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it possible to reuse the constant. In addition, change the type from i32 to usize since the value describes a size. Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Signed-off-by: Jan Höppner --- rust/pv/src/req.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rust/pv/src/req.rs b/rust/pv/src/req.rs index 125bd4ca..588d9cc0 100644 --- a/rust/pv/src/req.rs +++ b/rust/pv/src/req.rs @@ -275,16 +275,17 @@ impl AsRef<[u8]> for EcdhPubkeyCoord { } } +const ECDH_PUB_KEY_COORD_POINT_SIZE: usize = 0x50; + /// Get the pub ECDH coordinates in the format the Ultravisor expects it: /// The two coordinates are padded to 80 bytes each. fn get_pub_ecdh_points(pkey: &EcPointRef, grp: &EcGroupRef) -> Result<[u8; 160], ErrorStack> { - const ECDH_PUB_KEY_COORD_POINT_SIZE: i32 = 0x50; let mut x = BigNum::new()?; let mut y = BigNum::new()?; let mut bn_ctx = BigNumContext::new()?; pkey.affine_coordinates(grp, &mut x, &mut y, &mut bn_ctx)?; - let mut coord: Vec = x.to_vec_padded(ECDH_PUB_KEY_COORD_POINT_SIZE)?; - coord.append(&mut y.to_vec_padded(ECDH_PUB_KEY_COORD_POINT_SIZE)?); + let mut coord: Vec = x.to_vec_padded(ECDH_PUB_KEY_COORD_POINT_SIZE as i32)?; + coord.append(&mut y.to_vec_padded(ECDH_PUB_KEY_COORD_POINT_SIZE as i32)?); Ok(coord.try_into().unwrap()) }