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
+1
-1
@@ -149,7 +149,7 @@ impl BootHdrTags {
|
||||
let mut tag = [0u8; BootHdrHead::TAG_SIZE];
|
||||
img.read_exact(tag.as_mut_slice())?;
|
||||
|
||||
Ok(BootHdrTags {
|
||||
Ok(Self {
|
||||
pld: hdr_head.pld,
|
||||
ald: hdr_head.ald,
|
||||
tld: hdr_head.tld,
|
||||
|
||||
@@ -68,7 +68,7 @@ impl<C: Zeroize> Confidential<C> {
|
||||
///
|
||||
/// Prefer using [`Into`]
|
||||
pub fn new(v: C) -> Self {
|
||||
Confidential(v)
|
||||
Self(v)
|
||||
}
|
||||
|
||||
/// Get a reference to the contained value
|
||||
@@ -100,8 +100,8 @@ impl<C: Zeroize + Debug> Debug for Confidential<C> {
|
||||
}
|
||||
|
||||
impl<C: Zeroize> From<C> for Confidential<C> {
|
||||
fn from(v: C) -> Confidential<C> {
|
||||
Confidential(v)
|
||||
fn from(v: C) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ impl fmt::Debug for AkidCheckResult {
|
||||
}
|
||||
|
||||
impl AkidCheckResult {
|
||||
pub const OK: AkidCheckResult = AkidCheckResult(openssl_sys::X509_V_OK);
|
||||
pub const OK: Self = Self(openssl_sys::X509_V_OK);
|
||||
|
||||
/// Creates an `AkidCheckResult` from a raw error number.
|
||||
unsafe fn from_raw(err: c_int) -> AkidCheckResult {
|
||||
AkidCheckResult(err)
|
||||
unsafe fn from_raw(err: c_int) -> Self {
|
||||
Self(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ impl X509StoreContextExtension for X509StoreContextRef {
|
||||
with_context: F,
|
||||
) -> Result<T, ErrorStack>
|
||||
where
|
||||
F: FnOnce(&mut X509StoreContextRef) -> Result<T, ErrorStack>,
|
||||
F: FnOnce(&mut Self) -> Result<T, ErrorStack>,
|
||||
{
|
||||
struct Cleanup<'a>(&'a mut X509StoreContextRef);
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ impl ForeignType for StackableX509Crl {
|
||||
type CType = openssl_sys::X509_CRL;
|
||||
type Ref = X509CrlRef;
|
||||
|
||||
unsafe fn from_ptr(ptr: *mut openssl_sys::X509_CRL) -> StackableX509Crl {
|
||||
StackableX509Crl(ptr)
|
||||
unsafe fn from_ptr(ptr: *mut openssl_sys::X509_CRL) -> Self {
|
||||
Self(ptr)
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> *mut openssl_sys::X509_CRL {
|
||||
@@ -132,7 +132,7 @@ impl From<X509Crl> for StackableX509Crl {
|
||||
fn from(value: X509Crl) -> Self {
|
||||
unsafe {
|
||||
openssl_sys::X509_CRL_up_ref(value.as_ptr());
|
||||
StackableX509Crl::from_ptr(value.as_ptr())
|
||||
Self::from_ptr(value.as_ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ impl From<StackableX509Crl> for X509Crl {
|
||||
fn from(value: StackableX509Crl) -> Self {
|
||||
unsafe {
|
||||
openssl_sys::X509_CRL_up_ref(value.as_ptr());
|
||||
X509Crl::from_ptr(value.as_ptr())
|
||||
Self::from_ptr(value.as_ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ impl ReqEncrCtx {
|
||||
let prot_key = prot_key
|
||||
.into()
|
||||
.unwrap_or(SymKey::random(SymKeyType::Aes256)?);
|
||||
Ok(ReqEncrCtx {
|
||||
Ok(Self {
|
||||
iv,
|
||||
priv_key,
|
||||
prot_key,
|
||||
|
||||
@@ -247,7 +247,7 @@ impl TryFrom<u32> for AttestationVersion {
|
||||
|
||||
impl From<AttestationVersion> for RequestVersion {
|
||||
fn from(val: AttestationVersion) -> Self {
|
||||
val as RequestVersion
|
||||
val as Self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ assert_size!(ReqAuthData, 0x1e8);
|
||||
|
||||
impl ReqAuthData {
|
||||
fn new<F: Into<UvFlags>>(boot_tags: BootHdrTags, flags: F) -> Self {
|
||||
ReqAuthData {
|
||||
Self {
|
||||
flags: flags.into(),
|
||||
boot_tags,
|
||||
cuid: [0; 0x10],
|
||||
@@ -102,7 +102,7 @@ pub enum AddSecretVersion {
|
||||
|
||||
impl From<AddSecretVersion> for RequestVersion {
|
||||
fn from(val: AddSecretVersion) -> Self {
|
||||
val as RequestVersion
|
||||
val as Self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ impl AddSecretRequest {
|
||||
boot_tags: BootHdrTags,
|
||||
flags: AddSecretFlags,
|
||||
) -> Self {
|
||||
AddSecretRequest {
|
||||
Self {
|
||||
conf: ReqConfData {
|
||||
extension_secret: Confidential::new([0; 32]),
|
||||
secret,
|
||||
|
||||
@@ -47,7 +47,7 @@ impl GuestSecret {
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if OpenSSL cannot create a hash.
|
||||
pub fn association<O>(name: &str, secret: O) -> Result<GuestSecret>
|
||||
pub fn association<O>(name: &str, secret: O) -> Result<Self>
|
||||
where
|
||||
O: Into<Option<[u8; ASSOC_SECRET_SIZE]>>,
|
||||
{
|
||||
@@ -60,7 +60,7 @@ impl GuestSecret {
|
||||
None => random_array()?,
|
||||
};
|
||||
|
||||
Ok(GuestSecret::Association {
|
||||
Ok(Self::Association {
|
||||
name: name.to_string(),
|
||||
id: id.into(),
|
||||
secret: secret.into(),
|
||||
@@ -70,15 +70,15 @@ impl GuestSecret {
|
||||
/// Reference to the confidential data
|
||||
pub(crate) fn confidential(&self) -> &[u8] {
|
||||
match &self {
|
||||
GuestSecret::Null => &[],
|
||||
GuestSecret::Association { secret, .. } => secret.value().as_slice(),
|
||||
Self::Null => &[],
|
||||
Self::Association { secret, .. } => secret.value().as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the non-confidential part of the secret ad-hoc
|
||||
pub(crate) fn auth(&self) -> SecretAuth {
|
||||
match &self {
|
||||
GuestSecret::Null => SecretAuth::Null,
|
||||
Self::Null => SecretAuth::Null,
|
||||
// Panic: every non null secret type is listable -> no panic
|
||||
listable => {
|
||||
SecretAuth::Listable(ListableSecretHdr::from_guest_secret(listable).unwrap())
|
||||
@@ -90,24 +90,24 @@ impl GuestSecret {
|
||||
fn kind(&self) -> u16 {
|
||||
match self {
|
||||
// Null is not listable, but the ListableSecretType provides the type constant (1)
|
||||
GuestSecret::Null => ListableSecretType::NULL,
|
||||
GuestSecret::Association { .. } => ListableSecretType::ASSOCIATION,
|
||||
Self::Null => ListableSecretType::NULL,
|
||||
Self::Association { .. } => ListableSecretType::ASSOCIATION,
|
||||
}
|
||||
}
|
||||
|
||||
/// Size of the secret value
|
||||
fn secret_len(&self) -> u32 {
|
||||
match self {
|
||||
GuestSecret::Null => 0,
|
||||
GuestSecret::Association { secret, .. } => secret.value().len() as u32,
|
||||
Self::Null => 0,
|
||||
Self::Association { secret, .. } => secret.value().len() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the ID of the secret type (if any)
|
||||
fn id(&self) -> Option<SecretId> {
|
||||
match self {
|
||||
GuestSecret::Null => None,
|
||||
GuestSecret::Association { id, .. } => Some(id.to_owned()),
|
||||
Self::Null => None,
|
||||
Self::Association { id, .. } => Some(id.to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ impl GuestSecret {
|
||||
impl Display for GuestSecret {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
GuestSecret::Null => write!(f, "Meta"),
|
||||
Self::Null => write!(f, "Meta"),
|
||||
gs => {
|
||||
let kind: U16<BigEndian> = gs.kind().into();
|
||||
let st: ListableSecretType = kind.into();
|
||||
@@ -134,8 +134,8 @@ pub(crate) enum SecretAuth {
|
||||
impl SecretAuth {
|
||||
pub fn get(&self) -> &[u8] {
|
||||
match self {
|
||||
SecretAuth::Null => &[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
SecretAuth::Listable(h) => h.as_bytes(),
|
||||
Self::Null => &[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
Self::Listable(h) => h.as_bytes(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ impl UserData {
|
||||
pub(super) fn sign(&self, buf: &mut [u8], user_data_offset: usize) -> Result<()> {
|
||||
// get signing info or return if no signature is required
|
||||
let signed_data = match self {
|
||||
UserData::Null | UserData::Unsigned(_) => return Ok(()),
|
||||
UserData::Signed(s) => s,
|
||||
Self::Null | Self::Unsigned(_) => return Ok(()),
|
||||
Self::Signed(s) => s,
|
||||
};
|
||||
debug_assert!(buf.len() >= USER_DATA_SIZE);
|
||||
|
||||
@@ -194,9 +194,9 @@ impl UserData {
|
||||
/// 512 bytes
|
||||
pub(super) fn data(&self) -> (Option<&[u8]>, Option<Vec<u8>>) {
|
||||
let buf = match self {
|
||||
UserData::Null => None,
|
||||
UserData::Unsigned(d) => Some(d),
|
||||
UserData::Signed(SignedUserData { data, .. }) => Some(data),
|
||||
Self::Null => None,
|
||||
Self::Unsigned(d) => Some(d),
|
||||
Self::Signed(SignedUserData { data, .. }) => Some(data),
|
||||
};
|
||||
|
||||
let remaining_size = Self::USER_DATA_SIZE - buf.map(|b| b.len()).unwrap_or(0);
|
||||
|
||||
Reference in New Issue
Block a user