Skip to content
......@@ -22,6 +22,9 @@ pub enum CvfsErrors {
RmpEncode(String),
/// A deserialisation error occured
RmpDecode(String),
/// CryptoVfsInner was dropped before SecureFileHandler
CVFSAlreadyDropped(&'static str),
}
pub fn specify_io_error<O>(r: Result<O, std::io::Error>, reason: &'static str) -> CvfsResult<O> {
......
......@@ -118,7 +118,7 @@ pub struct CryptoVfsInner {
//this: Weak<Mutex<CryptoVfsInner>>,
keys: LiveKeys,
metadata: Metadata,
file_tag_counter: usize, //AtomicUsize,
file_tag_counter: u64, //AtomicUsize,
real_base_path: PathBuf,
}
impl CryptoVfsInner {
......
......@@ -131,9 +131,9 @@ impl core::fmt::Debug for FileInfo {
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FileTag(pub(crate) usize);
pub struct FileTag(pub(crate) u64);
impl FileTag {
pub fn next(file_tag_counter: &mut usize) -> Self {
pub fn next(file_tag_counter: &mut u64) -> Self {
//FileTag(file_tag_counter.fetch_add(1, Ordering::SeqCst))
let id = file_tag_counter.clone();
*file_tag_counter += 1;
......
......@@ -184,30 +184,27 @@ pub struct SecureFileHandler {
}
impl SecureFileHandler {
pub fn try_write(&mut self, buffer: &[u8]) -> CvfsResult<usize> {
let arc = self
.cvfs
.upgrade()
.expect("CryptoVfsInner was dropped before SecureFileHandler");
let arc = self.cvfs.upgrade().ok_or(CvfsErrors::CVFSAlreadyDropped(
"try_write(): CryptoVfsInner was dropped before SecureFileHandler",
))?;
let mut cvfs = arc.lock().expect("Metadata Mutex poisened");
let file = cvfs.metadata.find_active_file(&self.id)?;
Ok(file.write(buffer)?)
}
pub fn try_read(&mut self, out_buffer: &mut [u8]) -> CvfsResult<usize> {
let arc = self
.cvfs
.upgrade()
.expect("Metadata was dropped before SecureFileHandler");
let arc = self.cvfs.upgrade().ok_or(CvfsErrors::CVFSAlreadyDropped(
"try_read(): Metadata was dropped before SecureFileHandler",
))?;
let mut cvfs = arc.lock().expect("CryptoVfsInner Mutex poisened");
let file = cvfs.metadata.find_active_file(&self.id)?;
Ok(file.read(out_buffer)?)
}
pub fn try_flush(&mut self) -> CvfsResult<()> {
let arc = self
.cvfs
.upgrade()
.expect("Metadata was dropped before SecureFileHandler");
let arc = self.cvfs.upgrade().ok_or(CvfsErrors::CVFSAlreadyDropped(
"try_flush(): Metadata was dropped before SecureFileHandler",
))?;
let mut cvfs = arc.lock().expect("CryptoVfsInner Mutex poisened");
// splitting the CryptoVfsInner struct instead of the MutexGuard
let cvfs: &mut CryptoVfsInner = &mut cvfs;
......@@ -222,10 +219,9 @@ impl SecureFileHandler {
///
/// The cursor is not changed and may be hanging over the end, use the `Seek` methods like `Seek.rewind()` for that.
pub fn set_len(&mut self, size: usize) -> CvfsResult<()> {
let arc = self
.cvfs
.upgrade()
.expect("Metadata was dropped before SecureFileHandler");
let arc = self.cvfs.upgrade().ok_or(CvfsErrors::CVFSAlreadyDropped(
"set_len(): Metadata was dropped before SecureFileHandler",
))?;
let mut cvfs = arc.lock().expect("CryptoVfsInner Mutex poisened");
let file = cvfs.metadata.find_active_file(&self.id)?;
......@@ -250,13 +246,8 @@ impl Read for SecureFileHandler {
}
impl Drop for SecureFileHandler {
fn drop(&mut self) {
if let Err(error) = self.try_flush() {
if panicking() {
eprintln!("SecureFileHandler::drop() -> {error:?}");
} else {
panic!("SecureFileHandler::drop() -> {error:?}");
}
}
// ignore errors since we can not do much at this point
let _ = self.try_flush();
}
}
......
......@@ -492,7 +492,7 @@ fn argon2_key_stream(
params.output_len((256 + 128 + 128) / 8)?;
let argon2 = Argon2::from(params.params()?);
let key_stream = argon2.hash_password(password, &salt)?;
let key_stream = argon2.hash_password(password, salt)?;
let output = key_stream.hash.expect("unable to produce key stream");
assert!(
64 <= output.len(),
......