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
impl EncryptionSelector
Sourcepub 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>
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.
Sourcepub fn default_policy() -> Self
pub fn default_policy() -> Self
The policy a file gets when nothing is configured: _unencrypted as the
exempting suffix, everything else encrypted.
Sourcepub fn is_unconfigured(&self) -> bool
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.
Sourcepub fn has_unencrypted_comment_regex(&self) -> bool
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.
Sourcepub fn encrypted_comment_would_be_skipped(&self, rendered: &str) -> bool
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.
Sourcepub fn select(
&self,
path: &AadPath,
comments_stack: &[Vec<String>],
is_comment: bool,
) -> Selection
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.