nuts_container/
info.rs

1// MIT License
2//
3// Copyright (c) 2022-2024 Robin Doer
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to
7// deal in the Software without restriction, including without limitation the
8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22
23use nuts_backend::Backend;
24
25use crate::cipher::Cipher;
26use crate::kdf::Kdf;
27
28/// Information from the container.
29#[derive(Debug, PartialEq)]
30pub struct Info<B: Backend> {
31    /// Information from the lower backend.
32    pub backend: B::Info,
33
34    /// The revision of the header.
35    pub revision: u32,
36
37    /// The cipher used for encryption.
38    pub cipher: Cipher,
39
40    /// The key derivation function.
41    pub kdf: Kdf,
42
43    /// The gross block size is the block size specified by the
44    /// [backend](Backend::block_size).
45    ///
46    /// This is the actual size of a block in the backend. Note that the number
47    /// of userdata bytes per block can be smaller! This is the net block size
48    /// ([`Info::bsize_net`]).
49    pub bsize_gross: u32,
50
51    /// The (net) block size of the container.
52    ///
53    /// The net block size is the number of bytes you can store in a block. It
54    /// can be less than the gross block size ([`Info::bsize_gross`]).
55    ///
56    /// Depending on the selected cipher, you need to store additional data in
57    /// a block. I.e. an AE-cipher results into a tag, which needs to be stored
58    /// additionally. Such data must be substracted from the gross block size
59    /// and results into the net block size.
60    pub bsize_net: u32,
61}