Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
radumarias committed May 20, 2024
1 parent 4f11f46 commit 82c1747
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 139 deletions.
8 changes: 4 additions & 4 deletions src/crypto/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ mod test {
let mut cursor = std::io::Cursor::new(vec![0; 0]);
let mut writer = crypto::create_writer(cursor, cipher, key.clone());
let data = "hello, this is my secret message";
writer.write_all(&data.as_bytes()).unwrap();
writer.write_all(data.as_bytes()).unwrap();
cursor = writer.finish().unwrap();
cursor.seek(io::SeekFrom::Start(0)).unwrap();
let mut reader = crypto::create_reader(cursor, cipher, key.clone());
Expand All @@ -883,7 +883,7 @@ mod test {
writer.write_all(&data).unwrap();
cursor = writer.finish().unwrap();
cursor.seek(std::io::SeekFrom::Start(0)).unwrap();
let mut reader = crypto::create_reader(cursor, cipher, key.clone());
let mut reader = crypto::create_reader(cursor, cipher, key);
let mut data2 = vec![];
reader.read_to_end(&mut data2).unwrap();
assert_eq!(data.len(), data2.len());
Expand All @@ -905,7 +905,7 @@ mod test {
let mut cursor = io::Cursor::new(vec![0; 0]);
let mut writer = crypto::create_writer(cursor, cipher, key.clone());
let mut cursor_random = io::Cursor::new(vec![0; len]);
crypto::create_rng().fill_bytes(&mut cursor_random.get_mut());
crypto::create_rng().fill_bytes(cursor_random.get_mut());
cursor_random.seek(io::SeekFrom::Start(0)).unwrap();
io::copy(&mut cursor_random, &mut writer).unwrap();
cursor = writer.finish().unwrap();
Expand All @@ -924,7 +924,7 @@ mod test {
writer.write_all(&data).unwrap();
cursor = writer.finish().unwrap();
cursor.seek(std::io::SeekFrom::Start(0)).unwrap();
let mut reader = crypto::create_reader(cursor, cipher, key.clone());
let mut reader = crypto::create_reader(cursor, cipher, key);
let mut data2 = vec![];
reader.read_to_end(&mut data2).unwrap();
assert_eq!(data.len(), data2.len());
Expand Down
13 changes: 9 additions & 4 deletions src/encryptedfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::time::{Duration, SystemTime};
use std::{fs, io};

use argon2::password_hash::rand_core::RngCore;
use async_trait::async_trait;
use futures_util::TryStreamExt;
use lru::LruCache;
use num_format::{Locale, ToFormattedString};
Expand Down Expand Up @@ -511,8 +512,9 @@ struct KeyProvider {
cipher: Cipher,
}

#[async_trait]
impl ValueProvider<SecretVec<u8>, FsError> for KeyProvider {
fn provide(&self) -> Result<SecretVec<u8>, FsError> {
async fn provide(&self) -> Result<SecretVec<u8>, FsError> {
let password = self
.password_provider
.get_password()
Expand All @@ -526,22 +528,25 @@ pub trait PasswordProvider: Send + Sync + 'static {
}

struct DirEntryNameCacheProvider {}
#[async_trait]
impl ValueProvider<Mutex<LruCache<String, SecretString>>, FsError> for DirEntryNameCacheProvider {
fn provide(&self) -> Result<Mutex<LruCache<String, SecretString>>, FsError> {
async fn provide(&self) -> Result<Mutex<LruCache<String, SecretString>>, FsError> {
Ok(Mutex::new(LruCache::new(NonZeroUsize::new(2000).unwrap())))
}
}

struct DirEntryMetaCacheProvider {}
#[async_trait]
impl ValueProvider<Mutex<DirEntryMetaCache>, FsError> for DirEntryMetaCacheProvider {
fn provide(&self) -> Result<Mutex<DirEntryMetaCache>, FsError> {
async fn provide(&self) -> Result<Mutex<DirEntryMetaCache>, FsError> {
Ok(Mutex::new(LruCache::new(NonZeroUsize::new(2000).unwrap())))
}
}

struct AttrCacheProvider {}
#[async_trait]
impl ValueProvider<Mutex<LruCache<u64, FileAttr>>, FsError> for AttrCacheProvider {
fn provide(&self) -> Result<Mutex<LruCache<u64, FileAttr>>, FsError> {
async fn provide(&self) -> Result<Mutex<LruCache<u64, FileAttr>>, FsError> {
Ok(Mutex::new(LruCache::new(NonZeroUsize::new(2000).unwrap())))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/encryptedfs/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn bench_exists_by_name(b: &mut Bencher) {
)
.unwrap();
});
})
});
});
});
}
Expand Down Expand Up @@ -106,7 +106,7 @@ fn bench_find_by_name(b: &mut Bencher) {
.await
.unwrap();
});
})
});
});
});
}
Expand Down Expand Up @@ -137,7 +137,7 @@ fn bench_read_dir(b: &mut Bencher) {
let vec: Vec<DirectoryEntry> = iter.map(|e| e.unwrap()).collect();
black_box(vec);
});
})
});
});
});
}
Expand Down Expand Up @@ -168,7 +168,7 @@ fn bench_read_dir_plus(b: &mut Bencher) {
let vec: Vec<DirectoryEntryPlus> = iter.map(|e| e.unwrap()).collect();
black_box(vec);
});
})
});
});
});
}
Loading

0 comments on commit 82c1747

Please sign in to comment.