pub struct EncryptedBackendBuilder<B> { /* private fields */ }Expand description
Settings of an EncryptedBackend, set through the methods below and
applied by build.
encrypt_names, block_size and long_name_threshold are stored in the
share’s marker. One that is left alone takes the share’s value, or for a
new share the default named on its method. case_insensitive and
name_cache_ttl are not stored and default to the values named on their
methods.
Implementations§
Source§impl<B: ShareBackend> EncryptedBackendBuilder<B>
impl<B: ShareBackend> EncryptedBackendBuilder<B>
Sourcepub fn encrypt_names(self, on: bool) -> Self
pub fn encrypt_names(self, on: bool) -> Self
Sets whether the names of files and directories are stored encrypted.
On for a new share unless set. A value that differs from the share’s
fails build with
SettingMismatch.
Sourcepub fn case_insensitive(self, on: bool) -> Self
pub fn case_insensitive(self, on: bool) -> Self
Sets whether names match without regard to case. On by default. It applies to encrypted names; with names in the clear the inner backend’s rule decides and this has no effect.
Sourcepub fn block_size(self, bytes: u32) -> Self
pub fn block_size(self, bytes: u32) -> Self
Sets the number of plaintext bytes in a block: a power of two from
8192 to 1048576. The default for a new share is 65536. Another value
fails build with
InvalidSetting, and one that
differs from the share’s with
SettingMismatch.
Sourcepub fn long_name_threshold(self, chars: u8) -> Self
pub fn long_name_threshold(self, chars: u8) -> Self
Sets the longest stored name in characters, from 62 to 255. A name
whose encrypted form is longer is stored under a short name made from
a hash, with the encrypted form in a second object beside it. The
default for a new share is 255. Another value, or any value together
with encrypt_names(false), fails
build with
InvalidSetting, and one that
differs from the share’s with
SettingMismatch.
Sourcepub fn name_cache_ttl(self, ttl: Duration) -> Self
pub fn name_cache_ttl(self, ttl: Duration) -> Self
Sets how long the decrypted names of a directory are trusted for
changes made outside this backend. The default is 30 seconds;
Duration::ZERO lists the directory again on every lookup that needs
it. The setting applies only to encrypted names that match without
regard to case.
Sourcepub fn restore_marker(self) -> Self
pub fn restore_marker(self) -> Self
Lets build write a new marker into a root that has
entries and no marker. Without it that root fails with
MarkerMissing.
The new marker takes the settings set on the builder, else the
defaults, so a share made with other settings has to be restored with
them. Before it writes the marker, build checks the key and the
block size against what the share holds. It does not check
encrypt_names or long_name_threshold, so keep a record of them.
With encrypted names, at least one entry of the root has to decode
under the key, and entries whose names do not decode are passed over.
Of the files, the first that holds data, found breadth first among at
most 10,000 entries, has to have a header of the chosen block size
and a first block that is a hole or verifies under the key. A share
with no such file passes. A failed check is
KeyMismatch, or
SettingMismatch for the block
size.
With names in the clear, a stray file such as .DS_Store can be the
file that is checked, and fails with KeyMismatch until it is
removed.
Sourcepub async fn build(self) -> Result<EncryptedBackend<B>, EncryptionError>
pub async fn build(self) -> Result<EncryptedBackend<B>, EncryptionError>
Checks the settings and the root of the inner backend, and returns the backend.
An empty root is a new share: build writes the marker, unless the
inner backend is read-only. A root with a marker is an existing share:
the key has to verify, and the settings set on the builder have to
equal the marker’s. Settings not set take the marker’s.
§Errors
Fails with an EncryptionError:
EncryptionError::InvalidSetting: a setting is out of range or clashes with another.EncryptionError::SettingMismatch: a setting differs from the share’s.EncryptionError::KeyMismatch: the key is not the share’s.EncryptionError::MarkerMissing: the root has entries and no marker.EncryptionError::MarkerInvalid: the marker is not a file of the right size, does not start with the marker magic, or holds field values out of range.EncryptionError::UnsupportedFormat: the marker has another format version.EncryptionError::Backend: the inner backend failed.EncryptionError::Random: the random generator failed.