From 62aa9b4351536a0bd0eeaae14878e0c3b691b3c2 Mon Sep 17 00:00:00 2001 From: wucke13 Date: Wed, 3 Jan 2024 18:32:09 +0100 Subject: [PATCH] fix: second round of clippy lints Clippy would not automatically apply these fixes, so they were applied by hand. --- constant-time/src/lib.rs | 2 +- secret-memory/src/public.rs | 2 +- secret-memory/src/secret.rs | 4 ++-- to/src/ops.rs | 12 ++++++------ util/src/file.rs | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/constant-time/src/lib.rs b/constant-time/src/lib.rs index f1a8c54..33908ba 100644 --- a/constant-time/src/lib.rs +++ b/constant-time/src/lib.rs @@ -16,7 +16,7 @@ use rosenpass_to::{with_destination, To}; /// /// If source and destination are of different sizes. #[inline] -pub fn xor<'a>(src: &'a [u8]) -> impl To<[u8], ()> + 'a { +pub fn xor(src: &[u8]) -> impl To<[u8], ()> + '_ { with_destination(|dst: &mut [u8]| { assert!(src.len() == dst.len()); for (dv, sv) in dst.iter_mut().zip(src.iter()) { diff --git a/secret-memory/src/public.rs b/secret-memory/src/public.rs index 39a43b8..342b367 100644 --- a/secret-memory/src/public.rs +++ b/secret-memory/src/public.rs @@ -20,7 +20,7 @@ pub struct Public { impl Public { /// Create a new [Public] from a byte slice pub fn from_slice(value: &[u8]) -> Self { - copy_slice(value).to_this(|| Self::zero()) + copy_slice(value).to_this(Self::zero) } /// Create a new [Public] from a byte array diff --git a/secret-memory/src/secret.rs b/secret-memory/src/secret.rs index bbaf090..0b2d993 100644 --- a/secret-memory/src/secret.rs +++ b/secret-memory/src/secret.rs @@ -83,7 +83,7 @@ impl Deref for ZeroizingSecretBox { type Target = T; fn deref(&self) -> &T { - &self.0.as_ref().unwrap() + self.0.as_ref().unwrap() } } @@ -177,7 +177,7 @@ impl Secret { /// Borrows the data pub fn secret(&self) -> &[u8; N] { - &self.storage.as_ref().unwrap() + self.storage.as_ref().unwrap() } /// Borrows the data mutably diff --git a/to/src/ops.rs b/to/src/ops.rs index cb4aad8..385c477 100644 --- a/to/src/ops.rs +++ b/to/src/ops.rs @@ -8,7 +8,7 @@ use crate::{with_destination, To}; /// # Panics /// /// This function will panic if the two slices have different lengths. -pub fn copy_slice<'a, T>(origin: &'a [T]) -> impl To<[T], ()> + 'a +pub fn copy_slice(origin: &[T]) -> impl To<[T], ()> + '_ where T: Copy, { @@ -23,7 +23,7 @@ where /// # Panics /// /// This function will panic if destination is shorter than origin. -pub fn copy_slice_least_src<'a, T>(origin: &'a [T]) -> impl To<[T], ()> + 'a +pub fn copy_slice_least_src(origin: &[T]) -> impl To<[T], ()> + '_ where T: Copy, { @@ -34,7 +34,7 @@ where /// destination. /// /// Copies as much data as is present in the shorter slice. -pub fn copy_slice_least<'a, T>(origin: &'a [T]) -> impl To<[T], ()> + 'a +pub fn copy_slice_least(origin: &[T]) -> impl To<[T], ()> + '_ where T: Copy, { @@ -47,7 +47,7 @@ where /// Function with destination that attempts to copy data from origin into the destination. /// /// Will return None if the slices are of different lengths. -pub fn try_copy_slice<'a, T>(origin: &'a [T]) -> impl To<[T], Option<()>> + 'a +pub fn try_copy_slice(origin: &[T]) -> impl To<[T], Option<()>> + '_ where T: Copy, { @@ -62,7 +62,7 @@ where /// Destination may be longer than origin. /// /// Will return None if the destination is shorter than origin. -pub fn try_copy_slice_least_src<'a, T>(origin: &'a [T]) -> impl To<[T], Option<()>> + 'a +pub fn try_copy_slice_least_src(origin: &[T]) -> impl To<[T], Option<()>> + '_ where T: Copy, { @@ -72,7 +72,7 @@ where } /// Function with destination that copies all data between two array references. -pub fn copy_array<'a, T, const N: usize>(origin: &'a [T; N]) -> impl To<[T; N], ()> + 'a +pub fn copy_array(origin: &[T; N]) -> impl To<[T; N], ()> + '_ where T: Copy, { diff --git a/util/src/file.rs b/util/src/file.rs index 4843382..48f8eb5 100644 --- a/util/src/file.rs +++ b/util/src/file.rs @@ -6,21 +6,21 @@ use std::{fs::OpenOptions, path::Path}; /// Open a file writable pub fn fopen_w>(path: P) -> std::io::Result { - Ok(OpenOptions::new() + OpenOptions::new() .read(false) .write(true) .create(true) .truncate(true) - .open(path)?) + .open(path) } /// Open a file readable pub fn fopen_r>(path: P) -> std::io::Result { - Ok(OpenOptions::new() + OpenOptions::new() .read(true) .write(false) .create(false) .truncate(false) - .open(path)?) + .open(path) } pub trait ReadExactToEnd {