Struct nuts_container::Container
source · pub struct Container<B: Backend> { /* private fields */ }
Expand description
The Container type.
A Container
acts like an encrypted block device, where you can read and
write encrypted blocks of data.
To create a new container use the Container::create
method. You can
open an existing container with the Container::open
method. With the
Container::read
and Container::write
methods you can read data from
the container resp. write data into the container.
Implementations§
source§impl<B: Backend> Container<B>
impl<B: Backend> Container<B>
sourcepub fn create(
backend_options: B::CreateOptions,
options: CreateOptions
) -> ContainerResult<Container<B>, B>
pub fn create( backend_options: B::CreateOptions, options: CreateOptions ) -> ContainerResult<Container<B>, B>
Creates a new container.
This method expects two arguments:
backend_options
, which is a type that implements theBackend::CreateOptions
trait. It acts as a builder for a concreteBackend
instance.options
, which is a builder of thisContainer
. ACreateOptions
instance can be created with theCreateOptionsBuilder
utility.
If encryption is turned on, you will be asked for a password over the password callback. The returned password is then used for encryption of the secure part of the header.
The header with the (possibly encrypted) secret is created and passed
to the Backend
. The header contains all information you need to
open the container again.
Errors
Errors are listed in the Error
type.
sourcepub fn open(
backend_options: B::OpenOptions,
options: OpenOptions
) -> ContainerResult<Container<B>, B>
pub fn open( backend_options: B::OpenOptions, options: OpenOptions ) -> ContainerResult<Container<B>, B>
Opens an existing container.
This method expects two arguments:
backend_options
, which is a type that implements theBackend::OpenOptions
trait. It acts as a builder for a concreteBackend
instance.options
, which is a builder of thisContainer
. AOpenOptions
instance can be created with theOpenOptionsBuilder
utility.
If encryption is turned on for the container, you will be asked for a password over the password callback. The returned password is then used to decrypt the secure part of the header.
Errors
Errors are listed in the Error
type.
sourcepub fn into_backend(self) -> B
pub fn into_backend(self) -> B
Consumes this container, returning the inner backend.
sourcepub fn info(&self) -> ContainerResult<Info<B>, B>
pub fn info(&self) -> ContainerResult<Info<B>, B>
sourcepub fn userdata(&self) -> &[u8] ⓘ
pub fn userdata(&self) -> &[u8] ⓘ
Returns userdata assigned to the container.
Userdata are arbitrary data stored in the (encrypted) header of the container. It can be used by a service running on top of a nuts container to store information about the service itself.
sourcepub fn update_userdata(&mut self, userdata: &[u8]) -> ContainerResult<(), B>
pub fn update_userdata(&mut self, userdata: &[u8]) -> ContainerResult<(), B>
sourcepub fn block_size(&self) -> u32
pub fn block_size(&self) -> u32
The (net) block size specifies the number of userdata bytes you can store in a block. It can be less than the gross block size specified by the backend!
Depending on the selected cipher, you need to store additional data in a block. I.e. an AE-cipher results into a tag, which needs to be stored additionally. Such data must be substracted from the gross block size and results into the net block size.
sourcepub fn aquire(&mut self) -> ContainerResult<B::Id, B>
pub fn aquire(&mut self) -> ContainerResult<B::Id, B>
sourcepub fn release(&mut self, id: B::Id) -> ContainerResult<(), B>
pub fn release(&mut self, id: B::Id) -> ContainerResult<(), B>
sourcepub fn read(&mut self, id: &B::Id, buf: &mut [u8]) -> ContainerResult<usize, B>
pub fn read(&mut self, id: &B::Id, buf: &mut [u8]) -> ContainerResult<usize, B>
Reads a block from the container.
Reads the block with the given id
and places the decrypted data in
buf
.
You cannot read not more data than block-size
bytes. If buf
is larger, than not the whole buffer is filled. In the
other direction, if buf
is not large enough to store the whole block,
buf
is filled with the first buf.len()
bytes.
The methods returns the number of bytes actually read, which cannot be greater than the block-size.
Errors
Errors are listed in the Error
type.
sourcepub fn write(&mut self, id: &B::Id, buf: &[u8]) -> ContainerResult<usize, B>
pub fn write(&mut self, id: &B::Id, buf: &[u8]) -> ContainerResult<usize, B>
Writes a block into the container.
Encrypts the plain data from buf
and writes the encrypted data into
the block with the given id
.
Writes up to buf.len()
bytes from the unencrypted buf
buffer into
the container.
If buf
is not large enough to fill the whole block, the destination
block is automatically padded with all zeros.
If buf
holds more data than the block-size, then the first
block-size bytes are copied into the block.
The method returns the number of bytes actually written.
Errors
Errors are listed in the Error
type.