mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv*: Move u8_to_hexstring to pv_core
Move pvapconfig::helper::u8_to_hexstring to pv_core::utils::encode_hex. Discard pvapconfig::helper::hexstring_to_u8 in favor of pv_core::utils::decode_hex. Signed-off-by: Jakob Naucke <naucke@linux.ibm.com> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
152f446d76
commit
66a10d5e3e
@@ -21,8 +21,9 @@ pub mod attest {
|
||||
pub mod misc {
|
||||
pub use crate::utils::pv_guest_bit_set;
|
||||
pub use crate::utils::{create_file, open_file, read_exact_file, read_file, write_file};
|
||||
pub use crate::utils::{decode_hex, parse_hex, to_u16, to_u32, try_parse_u128, try_parse_u64};
|
||||
pub use crate::utils::{decode_hex, encode_hex, parse_hex};
|
||||
pub use crate::utils::{read, write};
|
||||
pub use crate::utils::{to_u16, to_u32, try_parse_u128, try_parse_u64};
|
||||
pub use crate::utils::{Flags, Lsb0Flags64, Msb0Flags64};
|
||||
}
|
||||
|
||||
|
||||
@@ -355,6 +355,15 @@ usize_to_ui! {
|
||||
#[doc = r"u16"]
|
||||
=> u16, to_u16}
|
||||
|
||||
/// Converts the u8 slice into (lowercase) hexstring
|
||||
pub fn encode_hex<S: AsRef<[u8]>>(s: S) -> String {
|
||||
let slice = s.as_ref();
|
||||
let string = String::with_capacity(2 * slice.len());
|
||||
slice
|
||||
.iter()
|
||||
.fold(string, |acc, e| acc + &format!("{e:02x}"))
|
||||
}
|
||||
|
||||
/// Converts the hexstring into a byte vector.
|
||||
///
|
||||
/// # Errors
|
||||
@@ -504,6 +513,14 @@ mod tests {
|
||||
fn lsb_flags_unset_panic() {
|
||||
Lsb0Flags64::default().unset_bit(64)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_hex() {
|
||||
let arr = [0x12, 0x34, 0x56, 0xac, 0xbe, 0xf0];
|
||||
let exp = "123456acbef0";
|
||||
assert_eq!(super::encode_hex(arr), exp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_hex() {
|
||||
let s = "123456acbef0";
|
||||
|
||||
Reference in New Issue
Block a user