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)); let aes = AesGcm::<Aes256, cipher::consts::U16>::new(Key::from_slice(&key));
aes.decrypt_in_place_detached( aes.decrypt_in_place_detached(
GenericArray::from_slice(&nonce), GenericArray::from_slice(nonce),
&[0u8, 0, 0, 0, 0, 0, 0, 0], &[0u8, 0, 0, 0, 0, 0, 0, 0],
&mut buf, &mut buf,
GenericArray::from_slice(tag), GenericArray::from_slice(tag),
@ -141,10 +141,10 @@ impl ScryptObject {
let mut key = [0u8; 32]; let mut key = [0u8; 32];
let params = scrypt::Params::new((self.n as f64).log2() as u8, self.r, self.p) 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) 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); let hdkf = Hkdf::<sha2::Sha256>::new(None, &key);
hdkf.expand(b"AES-GCM file content encryption", &mut 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. /// Init a new ContentEnc from the master key and the iv len.
pub fn new(master_key: &[u8], iv_len: u8) -> Result<Self, ContentCipherError> { pub fn new(master_key: &[u8], iv_len: u8) -> Result<Self, ContentCipherError> {
let mut key = [0u8; 32]; 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)?; hdkf.expand(b"AES-GCM file content encryption", &mut key)?;
Ok(Self { Ok(Self {
@ -37,7 +37,7 @@ impl ContentEnc {
file_id: Option<&[u8]>, file_id: Option<&[u8]>,
) -> Result<Vec<u8>, ContentCipherError> { ) -> Result<Vec<u8>, ContentCipherError> {
// TODO NOT BOX // TODO NOT BOX
if block.len() == 0 { if block.is_empty() {
return Ok(block.into()); return Ok(block.into());
} }
@ -46,7 +46,7 @@ impl ContentEnc {
} }
if block.len() < self.iv_len { if block.len() < self.iv_len {
return Err(ContentCipherError::BlockTooShort().into()); return Err(ContentCipherError::BlockTooShort());
} }
let nonce = &block[..self.iv_len]; let nonce = &block[..self.iv_len];
@ -54,7 +54,7 @@ impl ContentEnc {
let ciphertext = &block[self.iv_len..block.len() - self.iv_len]; let ciphertext = &block[self.iv_len..block.len() - self.iv_len];
if nonce.iter().all(|f| *f == 0) { if nonce.iter().all(|f| *f == 0) {
return Err(ContentCipherError::AllZeroNonce().into()); return Err(ContentCipherError::AllZeroNonce());
} }
let mut buf = Vec::from(ciphertext); let mut buf = Vec::from(ciphertext);
@ -73,7 +73,7 @@ impl ContentEnc {
GenericArray::from_slice(tag), 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. /// Return the decrypted size of a file, based on the encrypted size.

View File

@ -1,13 +1,13 @@
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
/// EncodedFilename /// EncodedFilename
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum EncodedFilename { pub enum EncodedFilename {
ShortFilename(String), ShortFilename(String),
LongFilename(LongFilename), LongFilename(LongFilename),
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct LongFilename { pub struct LongFilename {
pub filename: String, pub filename: String,
pub filename_content: String, pub filename_content: String,
@ -33,11 +33,11 @@ impl From<String> for EncodedFilename {
} }
pub trait IntoDecodable { pub trait IntoDecodable {
fn to_decodable<'s>(&'s self) -> &'s str; fn to_decodable(&self) -> &str;
} }
impl IntoDecodable for EncodedFilename { impl IntoDecodable for EncodedFilename {
fn to_decodable<'s>(&'s self) -> &'s str { fn to_decodable(&self) -> &str {
match self { match self {
Self::ShortFilename(s) => s.as_str(), Self::ShortFilename(s) => s.as_str(),
Self::LongFilename(l) => l.filename_content.as_str(), Self::LongFilename(l) => l.filename_content.as_str(),
@ -46,13 +46,13 @@ impl IntoDecodable for EncodedFilename {
} }
impl IntoDecodable for String { impl IntoDecodable for String {
fn to_decodable<'s>(&'s self) -> &'s str { fn to_decodable(&self) -> &str {
self self
} }
} }
impl<'a> IntoDecodable for &'a str { impl<'a> IntoDecodable for &'a str {
fn to_decodable<'s>(&'s self) -> &'s str { fn to_decodable(&self) -> &str {
self self
} }
} }

View File

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

View File

@ -53,7 +53,7 @@ impl GocryptFs {
} }
/// Get the [`filename decoder`](struct@FilenameDecoder) attached to this 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 &self.filename_decoder
} }