fs_verity/
config.rs

1use num_enum::TryFromPrimitive;
2
3/// Maximum size of digests, as described [in the Linux kernel documentation](https://www.kernel.org/doc/html/latest/filesystems/fsverity.html#fs-verity-descriptor).
4pub const MAX_DIGEST_SIZE: usize = 64;
5
6/// Maximum size of salts, as described [in the Linux kernel documentation](https://www.kernel.org/doc/html/latest/filesystems/fsverity.html#fs-verity-descriptor)
7pub const MAX_SALT_SIZE: usize = 32;
8
9/// Linux has a hardcoded limit of 8, see `FS_VERITY_MAX_LEVELS` in `/fs/verity/fsverity_private.h` in the Linux source.
10/// In reality you are not likely to hit this limit ever, e.g. with SHA256 you'd need more than `usize::MAX` input bytes.
11pub const MAX_LEVELS: usize = 8;
12
13/// Currently the kernel requires the `fs-verity` block size to be equal to the system page size, which is usually 4096.
14/// Some modern 64 bit ARM systems [have a 64kB page size](https://www.kernel.org/doc/Documentation/arm64/memory.txt) though.
15pub const DEFAULT_BLOCK_SIZE: usize = 4096;
16
17// So we can have easy cross references in doc comments
18#[cfg(doc)]
19use super::*;
20
21/// Enum of the supported inner hash algorithms.
22/// 
23/// The [`Default`] value is `Sha256`, corresponding to the default hash algorithm in the `fsverity` tools, and to the
24/// default generic parameter of [`FsVerityDigest`].
25/// 
26/// This enum supports conversion to string using [`std::fmt::Display`] and from a string using [`parse_display::FromStr`].
27/// 
28/// It also supports conversion to integer using `as u8` and from integer using [`TryFromPrimitive`]). These integers values
29/// match the hash algorithm numbering used in the fsverity kernel API.
30#[derive(Copy, Clone, PartialEq, Eq, parse_display::FromStr, parse_display::Display, Debug, TryFromPrimitive)]
31#[display(style = "lowercase")]
32#[repr(u8)]
33pub enum InnerHashAlgorithm {
34    /// As string: `sha256`. As number: `FS_VERITY_HASH_ALG_SHA256` from the kernel API.
35    Sha256 = 1,
36
37    /// As string: `sha512`. As number: `FS_VERITY_HASH_ALG_SHA512` from the kernel API.
38    Sha512 = 2,
39}
40
41impl Default for InnerHashAlgorithm {
42    fn default() -> Self {
43        Self::Sha256
44    }
45}