Skip to main content

EncryptionSelector

Struct EncryptionSelector 

Source
pub struct EncryptionSelector { /* private fields */ }
Expand description

The compiled form of a file’s encryption policy.

Built once per file from the metadata so the regexes compile once instead of per leaf, and so a bad pattern is a named error at load time rather than a silently-non-matching regex at walk time. Upstream calls regexp.Match per leaf and discards the compile error (matched, _ :=), so an invalid pattern there behaves as “never matches” — which is the round-up this type removes.

Implementations§

Source§

impl EncryptionSelector

Source

pub fn new( unencrypted_suffix: Option<&str>, encrypted_suffix: Option<&str>, unencrypted_regex: Option<&str>, encrypted_regex: Option<&str>, unencrypted_comment_regex: Option<&str>, encrypted_comment_regex: Option<&str>, ) -> Result<Self, WireError>

Compile a policy. Every field is the metadata field of the same name; None/empty means “not configured”, matching upstream’s "" test.

Source

pub fn default_policy() -> Self

The policy a file gets when nothing is configured: _unencrypted as the exempting suffix, everything else encrypted.

Source

pub fn is_unconfigured(&self) -> bool

Whether any selector is configured at all.

Used to decide whether to fall back to Self::default_policy, which is what upstream does by defaulting UnencryptedSuffix when the whole set is empty.

Source

pub fn has_unencrypted_comment_regex(&self) -> bool

Whether unencrypted_comment_regex is set, which the encrypt path needs to know so it can refuse a self-defeating file.

Source

pub fn encrypted_comment_would_be_skipped(&self, rendered: &str) -> bool

Whether a rendered encrypted comment would match unencrypted_comment_regex — which would make the file permanently undecryptable, because the comment would be skipped on the way back in. Upstream refuses too.

Source

pub fn select( &self, path: &AadPath, comments_stack: &[Vec<String>], is_comment: bool, ) -> Selection

Decide one leaf.

comments_stack is the stack of active comment sets, innermost last — the shape upstream threads through its walker so that a comment can turn encryption on or off for the values that follow it. is_comment says whether the leaf is itself a comment, which only stage 6 cares about.

Trait Implementations§

Source§

impl Debug for EncryptionSelector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EncryptionSelector

Source§

fn default() -> EncryptionSelector

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.