Struct zbox::RepoOpener
[−]
[src]
pub struct RepoOpener { /* fields omitted */ }
A builder used to create a repository Repo
in various manners.
This builder exposes the ability to configure how a Repo
is opened and
what operations are permitted on the opened repository.
Generally speaking, when using RepoOpener
, you'll first call new
, then
chain calls to methods to set each option, then call open
, passing the
URI of the repository and password you're trying to open. This will give
you a Result
with a Repo
inside that you can further operate on.
Examples
Opening a repository and creating it if it doesn't exist.
use zbox::RepoOpener; let mut repo = RepoOpener::new().create(true).open("mem://foo", "pwd")?;
Specify parameters for creating a repository.
use zbox::{RepoOpener, OpsLimit, MemLimit, Cipher}; let mut repo = RepoOpener::new() .ops_limit(OpsLimit::Moderate) .mem_limit(MemLimit::Interactive) .cipher(Cipher::Xchacha) .create(true) .open("mem://foo", "pwd")?;
Methods
impl RepoOpener
[src]
fn new() -> Self
[src]
Creates a blank new set of options ready for configuration.
fn ops_limit(&mut self, ops_limit: OpsLimit) -> &mut Self
[src]
Sets the password hash operation limit.
This option is only used for creating a repository.
OpsLimit::Interactive
is the default.
fn mem_limit(&mut self, mem_limit: MemLimit) -> &mut Self
[src]
Sets the password hash memory limit.
This option is only used for creating a repository.
MemLimit::Interactive
is the default.
fn cipher(&mut self, cipher: Cipher) -> &mut Self
[src]
Sets the crypto cipher encrypts the repository.
This option is only used for creating a repository. Cipher::Aes
is
the default if hardware supports AES-NI instructions, otherwise it will
fall back to Cipher::Xchacha
.
fn create(&mut self, create: bool) -> &mut Self
[src]
Sets the option for creating a new repository.
This option indicates whether a new repository will be created if the repository does not yet already exist.
fn create_new(&mut self, create_new: bool) -> &mut Self
[src]
Sets the option to always create a new repository.
This option indicates whether a new repository will be created. No repository is allowed to exist at the target location.
fn read_only(&mut self, read_only: bool) -> &mut Self
[src]
Sets the option for read-only mode.
This option cannot be true with either create
or create_new
is true.
fn open(&self, uri: &str, pwd: &str) -> Result<Repo>
[src]
Opens a repository at URI with the password and options specified by
self
.
Currently two types of storages are supported:
OS file system based storage, location prefix is
file://
After the prefix is the path to a directory on OS file system. It can be a relative or absolute path.
Memory based storage, location prefix is
mem://
As memory stoage is volatile, it is always be used with
create
option. It doesn't make sense to open an existing memory storage, thus the string after prefix is arbitrary.
After a repository is opened, all of the other functions provided by Zbox will be thread-safe.
The application should destroy the password as soon as possible after calling this function.
Errors
Open a memory based repository without enable create
option will
return an error.