mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Run rustfmt with some experimental options
+ Sort and group the imports + Normalize and format comments (100 characters width) Command used: $ cargo +nightly fmt -- Acked-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Marc Hartmayer <marc@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
3d5f75d6c3
commit
f8fb9ce32a
@@ -5,14 +5,12 @@
|
||||
//! AP support functions
|
||||
//
|
||||
|
||||
use crate::{
|
||||
utils::{pv_guest_bit_set, read_file_string, write_file},
|
||||
Error, Result,
|
||||
};
|
||||
use std::{fmt, thread, time};
|
||||
|
||||
use regex::Regex;
|
||||
use std::fmt;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
|
||||
use crate::utils::{pv_guest_bit_set, read_file_string, write_file};
|
||||
use crate::{Error, Result};
|
||||
|
||||
const PATH_SYS_DEVICES_AP: &str = "/sys/devices/ap";
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ impl<T: Default> Zeroize for Vec<T> {
|
||||
|
||||
impl Zeroize for String {
|
||||
fn zeroize(&mut self) {
|
||||
// SAFETY: The Vec<u8> zerorize function overwrites memory with the zero byte -> still valid UTF-8
|
||||
// SAFETY: The Vec<u8> zerorize function overwrites memory with the zero byte -> still valid
|
||||
// UTF-8
|
||||
unsafe { self.as_mut_vec().zeroize() };
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -13,7 +13,6 @@ mod uvdevice;
|
||||
mod uvsecret;
|
||||
|
||||
pub use error::{Error, FileAccessErrorType, FileIoErrorType, Result};
|
||||
|
||||
/// Early Boot Customization (EBC) utilities.
|
||||
///
|
||||
/// This module provides types and functions for working with Early Boot
|
||||
@@ -28,13 +27,11 @@ pub mod attest {
|
||||
|
||||
/// Miscellaneous functions and definitions
|
||||
pub mod misc {
|
||||
pub use crate::utils::pv_guest_bit_set;
|
||||
pub use crate::utils::{create_file, open_file};
|
||||
pub use crate::utils::{decode_hex, encode_hex, parse_hex};
|
||||
pub use crate::utils::{read, write};
|
||||
pub use crate::utils::{read_exact_file, read_file, read_file_string, write_file};
|
||||
pub use crate::utils::{to_u16, to_u32, try_parse_u128, try_parse_u64};
|
||||
pub use crate::utils::{Flags, Lsb0Flags64, Msb0Flags64};
|
||||
pub use crate::utils::{
|
||||
create_file, decode_hex, encode_hex, open_file, parse_hex, pv_guest_bit_set, read,
|
||||
read_exact_file, read_file, read_file_string, to_u16, to_u32, try_parse_u128,
|
||||
try_parse_u64, write, write_file, Flags, Lsb0Flags64, Msb0Flags64,
|
||||
};
|
||||
}
|
||||
|
||||
/// Definitions and functions for interacting with the Ultravisor
|
||||
@@ -43,8 +40,9 @@ pub mod misc {
|
||||
/// [`crate::uv::UvCmd`]
|
||||
pub mod uv {
|
||||
pub use crate::uvdevice::attest::AttestationCmd;
|
||||
pub use crate::uvdevice::retr_secret::RetrievableSecret;
|
||||
pub use crate::uvdevice::retr_secret::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes};
|
||||
pub use crate::uvdevice::retr_secret::{
|
||||
AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, RetrievableSecret,
|
||||
};
|
||||
pub use crate::uvdevice::secret::{AddCmd, ListCmd, LockCmd, RetrieveCmd};
|
||||
pub use crate::uvdevice::secret_list::{ListableSecretType, SecretEntry, SecretId, SecretList};
|
||||
pub use crate::uvdevice::{ConfigUid, UvCmd, UvDevice, UvDeviceInfo, UvFlags, UvcSuccess};
|
||||
@@ -77,15 +75,12 @@ pub mod request {
|
||||
|
||||
/// Functionalities for reading add-secret requests
|
||||
pub mod secret {
|
||||
pub use crate::uvsecret::AddSecretMagic;
|
||||
pub use crate::uvsecret::UserDataType;
|
||||
pub use crate::uvsecret::{AddSecretMagic, UserDataType};
|
||||
}
|
||||
|
||||
/// Functionalities for the AP bus
|
||||
pub mod ap {
|
||||
pub use crate::apdevice::Apqn;
|
||||
pub use crate::apdevice::RE_QUEUE_DIR;
|
||||
pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state};
|
||||
pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state, Apqn, RE_QUEUE_DIR};
|
||||
/// AP modes
|
||||
pub mod apqn_mode {
|
||||
pub use crate::apdevice::ApqnMode::{self, *};
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// Copyright IBM Corp.
|
||||
|
||||
use std::fmt::{Display, Formatter, Result as Resfmt};
|
||||
use std::fs::File;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::from_utf8;
|
||||
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes};
|
||||
|
||||
use crate::misc::encode_hex;
|
||||
use crate::utils::open_file;
|
||||
use crate::{Error, Result};
|
||||
use std::{
|
||||
fmt::{Display, Formatter, Result as Resfmt},
|
||||
fs::File,
|
||||
os::unix::ffi::OsStrExt,
|
||||
path::{Path, PathBuf},
|
||||
str::from_utf8,
|
||||
};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes};
|
||||
|
||||
const HASH_LEN: usize = 32;
|
||||
// UserDataType::Unsigned.max() returns 512
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, U64};
|
||||
|
||||
use crate::{
|
||||
macros::{bail_spec, file_error},
|
||||
Error, FileAccessErrorType, Result,
|
||||
};
|
||||
use crate::macros::{bail_spec, file_error};
|
||||
use crate::{Error, FileAccessErrorType, Result};
|
||||
|
||||
/// Trait that describes bitflags, represented by `T`.
|
||||
pub trait Flags<T>: From<T> + for<'a> From<&'a T> {
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{request::MagicValue, Error};
|
||||
use zerocopy::U32;
|
||||
use zerocopy::{BigEndian, ByteOrder};
|
||||
use zerocopy::{BigEndian, ByteOrder, U32};
|
||||
|
||||
use crate::request::MagicValue;
|
||||
use crate::Error;
|
||||
|
||||
/// The magic value used to identify an attestation request
|
||||
///
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
use crate::FileAccessErrorType;
|
||||
use crate::{Error, Result};
|
||||
use log::debug;
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
fs::File,
|
||||
os::unix::prelude::{AsRawFd, RawFd},
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use std::os::unix::prelude::{AsRawFd, RawFd};
|
||||
|
||||
#[cfg(not(test))]
|
||||
use ::libc::ioctl;
|
||||
use log::debug;
|
||||
#[cfg(test)]
|
||||
use test::mock_libc::ioctl;
|
||||
|
||||
use crate::{Error, FileAccessErrorType, Result};
|
||||
|
||||
/// Contains the rust representation of asm/uvdevice.h
|
||||
/// from kernel version: 6.5 verify
|
||||
mod ffi;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
use std::ptr;
|
||||
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
use super::{ffi, AttestationUserData, ConfigUid, UvCmd};
|
||||
use crate::{Error, Result};
|
||||
use std::ptr;
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
/// _Retrieve Attestation Measurement_ UVC
|
||||
///
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
use crate::{assert_size, static_assert};
|
||||
use zerocopy::{FromBytes, IntoBytes};
|
||||
|
||||
use crate::{assert_size, static_assert};
|
||||
|
||||
pub const UVIO_ATT_ARCB_MAX_LEN: usize = 0x100000;
|
||||
pub const UVIO_ATT_MEASUREMENT_MAX_LEN: usize = 0x8000;
|
||||
pub const UVIO_ATT_ADDITIONAL_MAX_LEN: usize = 0x8000;
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi::{self, uvio_uvdev_info};
|
||||
use crate::{
|
||||
misc::{Flags, Lsb0Flags64},
|
||||
uv::{UvCmd, UvDevice},
|
||||
Result,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
|
||||
use zerocopy::{FromZeros, IntoBytes};
|
||||
|
||||
use super::ffi::{self, uvio_uvdev_info};
|
||||
use crate::misc::{Flags, Lsb0Flags64};
|
||||
use crate::uv::{UvCmd, UvDevice};
|
||||
use crate::Result;
|
||||
|
||||
/// Information of supported functions by the uvdevice
|
||||
///
|
||||
/// * `supp_uvio_cmds` - supported IOCTLs by this device
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::uv::{ListableSecretType, RetrieveCmd};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
|
||||
use crate::uv::{ListableSecretType, RetrieveCmd};
|
||||
|
||||
/// Allowed sizes for AES keys
|
||||
#[non_exhaustive]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
@@ -335,8 +337,8 @@ mod test {
|
||||
assert_tokens(&retr, &[Token::Str("19 (EC-SECP521R1-PRIVATE-KEY)")]);
|
||||
}
|
||||
|
||||
// Ensure that the string representation of the retrievable types stay constant, or PEM will have
|
||||
// different, incompatible types
|
||||
// Ensure that the string representation of the retrievable types stay constant, or PEM will
|
||||
// have different, incompatible types
|
||||
#[test]
|
||||
fn stable_type_names() {
|
||||
assert_eq!("PLAINTEXT", RetrievableSecret::PlainText.to_string());
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use super::ffi;
|
||||
use crate::{
|
||||
request::{Confidential, MagicValue},
|
||||
uv::{SecretEntry, UvCmd},
|
||||
uvsecret::AddSecretMagic,
|
||||
Error, Result, PAGESIZE,
|
||||
};
|
||||
use std::io::Read;
|
||||
use std::mem::size_of_val;
|
||||
|
||||
use log::debug;
|
||||
use std::{io::Read, mem::size_of_val};
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::ffi;
|
||||
use crate::request::{Confidential, MagicValue};
|
||||
use crate::uv::{SecretEntry, UvCmd};
|
||||
use crate::uvsecret::AddSecretMagic;
|
||||
use crate::{Error, Result, PAGESIZE};
|
||||
|
||||
/// _List Secrets_ Ultravisor command.
|
||||
///
|
||||
/// The List Secrets Ultravisor call is used to list the
|
||||
|
||||
@@ -2,24 +2,20 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2024
|
||||
|
||||
use crate::{
|
||||
assert_size,
|
||||
uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret},
|
||||
uvdevice::UvCmd,
|
||||
Error, Result,
|
||||
};
|
||||
use std::cmp::min;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::{Debug, Display, LowerHex, UpperHex};
|
||||
use std::io::{Cursor, Read, Seek, Write};
|
||||
use std::mem::size_of;
|
||||
use std::slice::Iter;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::{
|
||||
cmp::min,
|
||||
ffi::CStr,
|
||||
fmt::{Debug, Display, LowerHex, UpperHex},
|
||||
io::{Cursor, Read, Seek, Write},
|
||||
mem::size_of,
|
||||
slice::Iter,
|
||||
vec::IntoIter,
|
||||
};
|
||||
use zerocopy::{BigEndian, ByteOrder};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32};
|
||||
use zerocopy::{BigEndian, ByteOrder, FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32};
|
||||
|
||||
use crate::uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret};
|
||||
use crate::uvdevice::UvCmd;
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
/// The 32 byte long ID of an UV secret
|
||||
///
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::{c_int, c_ulong},
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
use std::ffi::{c_int, c_ulong};
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::*;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
/// needed to serialize all tests as tests operate on static data required by the mock
|
||||
@@ -129,8 +128,8 @@ impl UvCmd for TestCmd {
|
||||
}
|
||||
|
||||
impl UvDevice {
|
||||
/// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never touches the
|
||||
/// passed file
|
||||
/// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never
|
||||
/// touches the passed file
|
||||
fn test_dev() -> Self {
|
||||
Self(File::open(".").unwrap())
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
//
|
||||
// Copyright IBM Corp. 2023
|
||||
|
||||
use crate::assert_size;
|
||||
use crate::{
|
||||
request::{MagicValue, RequestMagic},
|
||||
Error, Result,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
use std::mem::size_of;
|
||||
|
||||
use byteorder::ByteOrder;
|
||||
use std::{fmt::Display, mem::size_of};
|
||||
use zerocopy::{BigEndian, Immutable, IntoBytes, U16};
|
||||
|
||||
use crate::request::{MagicValue, RequestMagic};
|
||||
use crate::{assert_size, Error, Result};
|
||||
|
||||
/// The magic value used to identify an `AddSecretRequest`.
|
||||
///
|
||||
/// The magic value is ASCII:
|
||||
@@ -145,11 +145,9 @@ impl From<UserDataType> for AddSecretMagic {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{
|
||||
request::MagicValue,
|
||||
secret::{AddSecretMagic, UserDataType},
|
||||
Error,
|
||||
};
|
||||
use crate::request::MagicValue;
|
||||
use crate::secret::{AddSecretMagic, UserDataType};
|
||||
use crate::Error;
|
||||
|
||||
#[test]
|
||||
fn convert_user_data() {
|
||||
|
||||
Reference in New Issue
Block a user