mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Use Self wherever possible
Use Self instead of the struct name whenever possible. Automagically replace struct name with Self: `cargo clippy --fix -- -W clippy::use_self` This streamlines the code. Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-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
300f8d23b5
commit
d30d272523
@@ -37,7 +37,7 @@ impl AttestationMeasAlg {
|
||||
/// Report the expected size for a given measurement algorithm
|
||||
pub const fn exp_size(&self) -> u32 {
|
||||
match self {
|
||||
AttestationMeasAlg::HmacSha512 => 64,
|
||||
Self::HmacSha512 => 64,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ impl<E: ByteOrder> TryFrom<U32<E>> for AttestationMeasAlg {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: U32<E>) -> Result<Self, Self::Error> {
|
||||
if value.get() == AttestationMeasAlg::HmacSha512 as u32 {
|
||||
if value.get() == Self::HmacSha512 as u32 {
|
||||
Ok(Self::HmacSha512)
|
||||
} else {
|
||||
Err(Error::BinArcbInvAlgorithm(value.get()))
|
||||
|
||||
@@ -204,10 +204,10 @@ impl UvDevice {
|
||||
std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(UvDevice::PATH)
|
||||
.open(Self::PATH)
|
||||
.map_err(|e| Error::FileAccess {
|
||||
ty: FileAccessErrorType::Open,
|
||||
path: (UvDevice::PATH).into(),
|
||||
path: (Self::PATH).into(),
|
||||
source: e,
|
||||
})?,
|
||||
))
|
||||
|
||||
@@ -100,18 +100,18 @@ impl AttestationCmd {
|
||||
Self::verify_size(
|
||||
exp_measurement,
|
||||
1,
|
||||
AttestationCmd::MEASUREMENT_MAX_SIZE,
|
||||
Self::MEASUREMENT_MAX_SIZE,
|
||||
"Expected measurement size",
|
||||
)?;
|
||||
Self::verify_size(
|
||||
exp_additional,
|
||||
0,
|
||||
AttestationCmd::ADDITIONAL_MAX_SIZE,
|
||||
Self::ADDITIONAL_MAX_SIZE,
|
||||
"Expected additional data size",
|
||||
)?;
|
||||
Self::verify_slice(&arcb, AttestationCmd::ARCB_MAX_SIZE, "Attestation request")?;
|
||||
Self::verify_slice(&arcb, Self::ARCB_MAX_SIZE, "Attestation request")?;
|
||||
if let Some(ref data) = user_data {
|
||||
Self::verify_slice(data, AttestationCmd::USER_MAX_SIZE, "User data")?;
|
||||
Self::verify_slice(data, Self::USER_MAX_SIZE, "User data")?;
|
||||
}
|
||||
|
||||
let (user_len, user_data) = match user_data {
|
||||
|
||||
@@ -60,8 +60,8 @@ impl Display for SecretId {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; SecretId::ID_SIZE]> for SecretId {
|
||||
fn from(value: [u8; SecretId::ID_SIZE]) -> Self {
|
||||
impl From<[u8; Self::ID_SIZE]> for SecretId {
|
||||
fn from(value: [u8; Self::ID_SIZE]) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
@@ -251,8 +251,8 @@ impl SecretList {
|
||||
impl TryFrom<ListCmd> for SecretList {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(mut list: ListCmd) -> Result<SecretList> {
|
||||
SecretList::decode(&mut Cursor::new(list.data().unwrap())).map_err(Error::InvSecretList)
|
||||
fn try_from(mut list: ListCmd) -> Result<Self> {
|
||||
Self::decode(&mut Cursor::new(list.data().unwrap())).map_err(Error::InvSecretList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ impl From<U16<BigEndian>> for ListableSecretType {
|
||||
match value.get() {
|
||||
Self::RESERVED_0 => Self::Invalid(Self::RESERVED_0),
|
||||
Self::NULL => Self::Invalid(Self::NULL),
|
||||
Self::ASSOCIATION => ListableSecretType::Association,
|
||||
Self::ASSOCIATION => Self::Association,
|
||||
n => Self::Unknown(n),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl AddSecretMagic {
|
||||
/// Get the magic value.
|
||||
pub fn get(&self) -> RequestMagic {
|
||||
let mut res = RequestMagic::default();
|
||||
debug_assert!(res.len() == size_of::<AddSecretMagic>());
|
||||
debug_assert!(res.len() == size_of::<Self>());
|
||||
// Panic: does not panic, buf is 8 bytes long
|
||||
self.write_to(&mut res).unwrap();
|
||||
res
|
||||
@@ -51,7 +51,7 @@ impl AddSecretMagic {
|
||||
///
|
||||
/// Returns [`None`] if the byte slice does not contain a valid magic value variant.
|
||||
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
|
||||
if !Self::starts_with_magic(bytes) || bytes.len() < size_of::<AddSecretMagic>() {
|
||||
if !Self::starts_with_magic(bytes) || bytes.len() < size_of::<Self>() {
|
||||
return Err(Error::NoAsrcb);
|
||||
}
|
||||
|
||||
@@ -89,11 +89,11 @@ impl UserDataType {
|
||||
/// Returns the maximum user-data size in bytes.
|
||||
pub fn max(&self) -> usize {
|
||||
match self {
|
||||
UserDataType::Null => 0,
|
||||
UserDataType::Unsigned => 512,
|
||||
UserDataType::SgnEcSECP521R1 => 256,
|
||||
UserDataType::SgnRsa2048 => 256,
|
||||
UserDataType::SgnRsa3072 => 128,
|
||||
Self::Null => 0,
|
||||
Self::Unsigned => 512,
|
||||
Self::SgnEcSECP521R1 => 256,
|
||||
Self::SgnRsa2048 => 256,
|
||||
Self::SgnRsa3072 => 128,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,16 +118,16 @@ impl TryFrom<u16> for UserDataType {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: u16) -> std::result::Result<Self, Self::Error> {
|
||||
if value == UserDataType::Null as u16 {
|
||||
Ok(UserDataType::Null)
|
||||
} else if value == UserDataType::Unsigned as u16 {
|
||||
Ok(UserDataType::Unsigned)
|
||||
} else if value == UserDataType::SgnEcSECP521R1 as u16 {
|
||||
Ok(UserDataType::SgnEcSECP521R1)
|
||||
} else if value == UserDataType::SgnRsa2048 as u16 {
|
||||
Ok(UserDataType::SgnRsa2048)
|
||||
} else if value == UserDataType::SgnRsa3072 as u16 {
|
||||
Ok(UserDataType::SgnRsa3072)
|
||||
if value == Self::Null as u16 {
|
||||
Ok(Self::Null)
|
||||
} else if value == Self::Unsigned as u16 {
|
||||
Ok(Self::Unsigned)
|
||||
} else if value == Self::SgnEcSECP521R1 as u16 {
|
||||
Ok(Self::SgnEcSECP521R1)
|
||||
} else if value == Self::SgnRsa2048 as u16 {
|
||||
Ok(Self::SgnRsa2048)
|
||||
} else if value == Self::SgnRsa3072 as u16 {
|
||||
Ok(Self::SgnRsa3072)
|
||||
} else {
|
||||
Err(Error::UnsupportedUserData(value))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user