From 61d07910e679178e76fc952fadcffb750c73f3b2 Mon Sep 17 00:00:00 2001 From: oupson Date: Sat, 8 Oct 2022 16:23:52 +0200 Subject: [PATCH] Cargo clippy in rustcryptfs-lib --- rustcryptfs-lib/src/config/mod.rs | 6 +++--- rustcryptfs-lib/src/content/mod.rs | 10 +++++----- rustcryptfs-lib/src/filename/filename_encoded.rs | 12 ++++++------ rustcryptfs-lib/src/filename/mod.rs | 2 +- rustcryptfs-lib/src/lib.rs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rustcryptfs-lib/src/config/mod.rs b/rustcryptfs-lib/src/config/mod.rs index e8ea895..5be2d69 100644 --- a/rustcryptfs-lib/src/config/mod.rs +++ b/rustcryptfs-lib/src/config/mod.rs @@ -86,7 +86,7 @@ impl CryptConf { let aes = AesGcm::::new(Key::from_slice(&key)); aes.decrypt_in_place_detached( - GenericArray::from_slice(&nonce), + GenericArray::from_slice(nonce), &[0u8, 0, 0, 0, 0, 0, 0, 0], &mut buf, GenericArray::from_slice(tag), @@ -141,10 +141,10 @@ impl ScryptObject { let mut key = [0u8; 32]; let params = scrypt::Params::new((self.n as f64).log2() as u8, self.r, self.p) - .map_err(|e| ScryptError::from(e))?; + .map_err(ScryptError::from)?; scrypt::scrypt(password, &base64::decode(&self.salt)?, ¶ms, &mut key) - .map_err(|e| ScryptError::from(e))?; + .map_err(ScryptError::from)?; let hdkf = Hkdf::::new(None, &key); hdkf.expand(b"AES-GCM file content encryption", &mut key)?; diff --git a/rustcryptfs-lib/src/content/mod.rs b/rustcryptfs-lib/src/content/mod.rs index b162095..f5d1811 100644 --- a/rustcryptfs-lib/src/content/mod.rs +++ b/rustcryptfs-lib/src/content/mod.rs @@ -20,7 +20,7 @@ impl ContentEnc { /// Init a new ContentEnc from the master key and the iv len. pub fn new(master_key: &[u8], iv_len: u8) -> Result { let mut key = [0u8; 32]; - let hdkf = Hkdf::::new(None, &master_key); + let hdkf = Hkdf::::new(None, master_key); hdkf.expand(b"AES-GCM file content encryption", &mut key)?; Ok(Self { @@ -37,7 +37,7 @@ impl ContentEnc { file_id: Option<&[u8]>, ) -> Result, ContentCipherError> { // TODO NOT BOX - if block.len() == 0 { + if block.is_empty() { return Ok(block.into()); } @@ -46,7 +46,7 @@ impl ContentEnc { } if block.len() < self.iv_len { - return Err(ContentCipherError::BlockTooShort().into()); + return Err(ContentCipherError::BlockTooShort()); } let nonce = &block[..self.iv_len]; @@ -54,7 +54,7 @@ impl ContentEnc { let ciphertext = &block[self.iv_len..block.len() - self.iv_len]; if nonce.iter().all(|f| *f == 0) { - return Err(ContentCipherError::AllZeroNonce().into()); + return Err(ContentCipherError::AllZeroNonce()); } let mut buf = Vec::from(ciphertext); @@ -73,7 +73,7 @@ impl ContentEnc { GenericArray::from_slice(tag), )?; - return Ok(buf.to_vec()); + Ok(buf.to_vec()) } /// Return the decrypted size of a file, based on the encrypted size. diff --git a/rustcryptfs-lib/src/filename/filename_encoded.rs b/rustcryptfs-lib/src/filename/filename_encoded.rs index dcac5e1..bbcf2de 100644 --- a/rustcryptfs-lib/src/filename/filename_encoded.rs +++ b/rustcryptfs-lib/src/filename/filename_encoded.rs @@ -1,13 +1,13 @@ use sha2::{Digest, Sha256}; /// EncodedFilename -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum EncodedFilename { ShortFilename(String), LongFilename(LongFilename), } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct LongFilename { pub filename: String, pub filename_content: String, @@ -33,11 +33,11 @@ impl From for EncodedFilename { } pub trait IntoDecodable { - fn to_decodable<'s>(&'s self) -> &'s str; + fn to_decodable(&self) -> &str; } impl IntoDecodable for EncodedFilename { - fn to_decodable<'s>(&'s self) -> &'s str { + fn to_decodable(&self) -> &str { match self { Self::ShortFilename(s) => s.as_str(), Self::LongFilename(l) => l.filename_content.as_str(), @@ -46,13 +46,13 @@ impl IntoDecodable for EncodedFilename { } impl IntoDecodable for String { - fn to_decodable<'s>(&'s self) -> &'s str { + fn to_decodable(&self) -> &str { self } } impl<'a> IntoDecodable for &'a str { - fn to_decodable<'s>(&'s self) -> &'s str { + fn to_decodable(&self) -> &str { self } } diff --git a/rustcryptfs-lib/src/filename/mod.rs b/rustcryptfs-lib/src/filename/mod.rs index 714ff81..8ec6d42 100644 --- a/rustcryptfs-lib/src/filename/mod.rs +++ b/rustcryptfs-lib/src/filename/mod.rs @@ -20,7 +20,7 @@ pub struct FilenameCipher { impl FilenameCipher { pub fn new(master_key: &[u8]) -> Result { let mut key = [0u8; 32]; - let hdkf = Hkdf::::new(None, &master_key); + let hdkf = Hkdf::::new(None, master_key); hdkf.expand(b"EME filename encryption", &mut key)?; Ok(Self { diff --git a/rustcryptfs-lib/src/lib.rs b/rustcryptfs-lib/src/lib.rs index 563bff5..5b13dfd 100644 --- a/rustcryptfs-lib/src/lib.rs +++ b/rustcryptfs-lib/src/lib.rs @@ -53,7 +53,7 @@ impl GocryptFs { } /// Get the [`filename decoder`](struct@FilenameDecoder) attached to this GocryptFs. - pub fn filename_decoder<'s>(&'s self) -> &'s FilenameCipher { + pub fn filename_decoder(&self) -> &FilenameCipher { &self.filename_decoder }