mod pac_man;
pub(crate) use pac_man::{encrypt_blob, 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 Spot {
bytes: Bytes,
}
#[allow(missing_debug_implementations)]
#[derive(Clone)]
pub(crate) struct Blob {
bytes: Bytes,
}
impl Spot {
pub(crate) fn new(bytes: Bytes) -> Result<Self> {
if bytes.len() >= MIN_ENCRYPTABLE_BYTES {
Err(Error::Generic(
"The provided bytes is too large to be a `Spot`".to_string(),
))
} else if bytes.is_empty() {
Err(Error::Generic("Cannot store empty bytes.".to_string()))
} else {
Ok(Self { bytes })
}
}
pub(crate) fn bytes(&self) -> Bytes {
self.bytes.clone()
}
}
impl Blob {
pub(crate) fn new(bytes: Bytes) -> Result<Self> {
if MIN_ENCRYPTABLE_BYTES > bytes.len() {
Err(Error::Generic(
"The provided bytes is too small to be a `Blob`".to_string(),
))
} else {
Ok(Self { bytes })
}
}
pub(crate) fn bytes(&self) -> Bytes {
self.bytes.clone()
}
}