#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum EncryptionAlgorithm {
Aes128,
Aes256,
}
#[derive(Debug, Clone, Copy)]
pub struct Permissions {
pub(crate) print: bool,
pub(crate) modify: bool,
pub(crate) copy: bool,
pub(crate) annotate: bool,
pub(crate) fill_forms: bool,
pub(crate) extract_accessibility: bool,
pub(crate) assemble: bool,
pub(crate) print_high_quality: bool,
}
impl Permissions {
pub const fn full_access() -> Self {
Self {
print: true,
modify: true,
copy: true,
annotate: true,
fill_forms: true,
extract_accessibility: true,
assemble: true,
print_high_quality: true,
}
}
pub const fn print_only() -> Self {
Self {
print: true,
modify: false,
copy: false,
annotate: false,
fill_forms: false,
extract_accessibility: true,
assemble: false,
print_high_quality: true,
}
}
pub const fn read_only() -> Self {
Self {
print: false,
modify: false,
copy: false,
annotate: false,
fill_forms: false,
extract_accessibility: true,
assemble: false,
print_high_quality: false,
}
}
pub const fn annotate() -> Self {
Self {
print: true,
modify: false,
copy: true,
annotate: true,
fill_forms: true,
extract_accessibility: true,
assemble: false,
print_high_quality: true,
}
}
pub const fn with_print(mut self, v: bool) -> Self {
self.print = v;
self
}
pub const fn with_modify(mut self, v: bool) -> Self {
self.modify = v;
self
}
pub const fn with_copy(mut self, v: bool) -> Self {
self.copy = v;
self
}
pub const fn with_annotate(mut self, v: bool) -> Self {
self.annotate = v;
self
}
pub const fn with_fill_forms(mut self, v: bool) -> Self {
self.fill_forms = v;
self
}
pub const fn with_extract_accessibility(mut self, v: bool) -> Self {
self.extract_accessibility = v;
self
}
pub const fn with_assemble(mut self, v: bool) -> Self {
self.assemble = v;
self
}
pub const fn with_print_high_quality(mut self, v: bool) -> Self {
self.print_high_quality = v;
self
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct EncryptOptions {
#[allow(dead_code)]
pub(crate) algorithm: EncryptionAlgorithm,
pub(crate) user_password: Option<String>,
pub(crate) owner_password: Option<String>,
pub(crate) permissions: Permissions,
}
impl Default for EncryptOptions {
fn default() -> Self {
Self::aes256()
}
}
impl EncryptOptions {
pub fn aes256() -> Self {
Self {
algorithm: EncryptionAlgorithm::Aes256,
user_password: None,
owner_password: None,
permissions: Permissions::full_access(),
}
}
pub fn aes128() -> Self {
Self {
algorithm: EncryptionAlgorithm::Aes128,
..Self::aes256()
}
}
pub fn with_user_password(mut self, pw: impl Into<String>) -> Self {
self.user_password = Some(pw.into());
self
}
pub fn with_owner_password(mut self, pw: impl Into<String>) -> Self {
self.owner_password = Some(pw.into());
self
}
pub fn with_permissions(mut self, p: Permissions) -> Self {
self.permissions = p;
self
}
}