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
// Error for writing

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

use crate::EncryptionError;

/// Block file write error
#[derive(Debug, Clone)]
pub enum BlockWriteError {
    /// Exceeded file size
    ExceededFileSize,
    /// Encryption error
    EncryptionError(EncryptionError),
    /// IO Error
    IoError(String),
}

impl Display for BlockWriteError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            BlockWriteError::ExceededFileSize => write!(f, "Exceeded file size"),
            BlockWriteError::EncryptionError(encryption_error) => {
                write!(f, "{}", encryption_error)
            }
            BlockWriteError::IoError(error) => write!(f, "{}", error),
        }
    }
}

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

impl From<EncryptionError> for BlockWriteError {
    fn from(value: EncryptionError) -> Self {
        BlockWriteError::EncryptionError(value)
    }
}