pmv_encryption_rs 1.0.0

Implementation of PersonalMediaVault encrypted storage model. This library allows to encrypt and decrypt data, and also read ans write files in the same format PersonalMediaVault uses.
Documentation
// Errors for reading

use std::{fmt::Display, io};

use crate::DecryptionError;

/// File open error
#[derive(Debug, Clone)]
pub enum BlockFileOpenError {
    /// Invalid block size
    InvalidBlockSize,
    /// IO Error
    IoError(String),
}

impl Display for BlockFileOpenError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            BlockFileOpenError::InvalidBlockSize => write!(f, "Invalid block size"),
            BlockFileOpenError::IoError(error) => write!(f, "{}", error),
        }
    }
}

impl From<io::Error> for BlockFileOpenError {
    fn from(value: io::Error) -> Self {
        BlockFileOpenError::IoError(value.to_string())
    }
}

/// File read error
#[derive(Debug, Clone)]
pub enum BlockFileReadError {
    /// Reached the end of the file
    EndOfFile,
    /// Position out of bounds
    OutOfBounds,
    /// Decryption error
    DecryptionError(DecryptionError),
    /// IO Error
    IoError(String),
}

impl Display for BlockFileReadError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            BlockFileReadError::EndOfFile => write!(f, "Reached the end of the file"),
            BlockFileReadError::OutOfBounds => write!(f, "Cursor position out of bounds"),
            BlockFileReadError::DecryptionError(decryption_error) => {
                write!(f, "{}", decryption_error)
            }
            BlockFileReadError::IoError(error) => write!(f, "{}", error),
        }
    }
}

impl From<io::Error> for BlockFileReadError {
    fn from(value: io::Error) -> Self {
        BlockFileReadError::IoError(value.to_string())
    }
}

impl From<DecryptionError> for BlockFileReadError {
    fn from(value: DecryptionError) -> Self {
        BlockFileReadError::DecryptionError(value)
    }
}