mod pac_man;
pub(crate) use pac_man::{encrypt_large, to_chunk, DataMapLevel};
use crate::client::{Error, Result};
use bytes::Bytes;
use self_encryption::MIN_ENCRYPTABLE_BYTES;
#[allow(missing_debug_implementations)]
#[derive(Clone)]
pub(crate) struct SmallFile {
bytes: Bytes,
}
#[allow(missing_debug_implementations)]
#[derive(Clone)]
pub(crate) struct LargeFile {
bytes: Bytes,
}
impl SmallFile {
pub(crate) fn new(bytes: Bytes) -> Result<Self> {
if bytes.len() >= MIN_ENCRYPTABLE_BYTES {
Err(Error::TooLargeAsSmallFile)
} else if bytes.is_empty() {
Err(Error::EmptyFileProvided)
} else {
Ok(Self { bytes })
}
}
pub(crate) fn bytes(&self) -> Bytes {
self.bytes.clone()
}
}
impl LargeFile {
pub(crate) fn new(bytes: Bytes) -> Result<Self> {
if MIN_ENCRYPTABLE_BYTES > bytes.len() {
Err(Error::TooSmallForSelfEncryption)
} else {
Ok(Self { bytes })
}
}
pub(crate) fn bytes(&self) -> Bytes {
self.bytes.clone()
}
}