use std::path::{Path, PathBuf};
use thiserror::Error;
use wildland_corex::dfs::interface::{DfsFrontendError, IStream, OStream};
pub trait EncryptionModule {
fn wrap_istream(&self, istream: Box<dyn IStream>) -> Box<dyn IStream>;
fn wrap_ostream(&self, ostream: Box<dyn OStream>) -> Box<dyn OStream>;
fn encode_data(&self, input: &[u8]) -> Result<Vec<u8>, EncryptionModuleError>;
fn encode_path(&self, input: &Path) -> Result<PathBuf, EncryptionModuleError>;
fn decode_data(&self, input: &[u8]) -> Result<Vec<u8>, EncryptionModuleError>;
fn decode_path(&self, input: &Path) -> Result<PathBuf, EncryptionModuleError>;
fn decode_plain(&self, input: String) -> Result<String, EncryptionModuleError>;
}
#[derive(Error, Debug)]
pub enum EncryptionModuleError {
#[error("Failed To Decode, data may be corrupted {0}")]
Decode(String),
#[error("Failed To Encode {0}")]
Encode(String),
#[error("UnknownError {0}")]
Unknown(String),
}
impl From<EncryptionModuleError> for DfsFrontendError {
fn from(e: EncryptionModuleError) -> Self {
match e {
EncryptionModuleError::Decode(msg) => DfsFrontendError::Encryption(msg),
EncryptionModuleError::Encode(msg) => DfsFrontendError::Encryption(msg),
EncryptionModuleError::Unknown(msg) => DfsFrontendError::Encryption(msg),
}
}
}
impl From<base64::DecodeError> for EncryptionModuleError {
fn from(e: base64::DecodeError) -> Self {
EncryptionModuleError::Decode(e.to_string())
}
}