Cargo clippy in rustcryptfs-lib

This commit is contained in:
oupson 2022-10-08 16:23:52 +02:00
parent 4b93f8071f
commit 61d07910e6
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
5 changed files with 16 additions and 16 deletions

View File

@ -86,7 +86,7 @@ impl CryptConf {
let aes = AesGcm::<Aes256, cipher::consts::U16>::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)?, &params, &mut key)
.map_err(|e| ScryptError::from(e))?;
.map_err(ScryptError::from)?;
let hdkf = Hkdf::<sha2::Sha256>::new(None, &key);
hdkf.expand(b"AES-GCM file content encryption", &mut key)?;

View File

@ -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<Self, ContentCipherError> {
let mut key = [0u8; 32];
let hdkf = Hkdf::<sha2::Sha256>::new(None, &master_key);
let hdkf = Hkdf::<sha2::Sha256>::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<Vec<u8>, 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.

View File

@ -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<String> 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
}
}

View File

@ -20,7 +20,7 @@ pub struct FilenameCipher {
impl FilenameCipher {
pub fn new(master_key: &[u8]) -> Result<Self, FilenameCipherError> {
let mut key = [0u8; 32];
let hdkf = Hkdf::<sha2::Sha256>::new(None, &master_key);
let hdkf = Hkdf::<sha2::Sha256>::new(None, master_key);
hdkf.expand(b"EME filename encryption", &mut key)?;
Ok(Self {

View File

@ -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
}