Skip to main content

luks/
error.rs

1//! Error type for LUKS parsing and unlocking.
2
3use std::io;
4
5/// Result alias for `luks-core`.
6pub type Result<T> = std::result::Result<T, LuksError>;
7
8/// A LUKS parse or unlock failure. Every variant names the offending value so an
9/// investigator can act on it (never a bare "invalid").
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum LuksError {
13    /// The `LUKS\xba\xbe` magic is absent — not a LUKS container.
14    #[error("not a LUKS container: magic is {found:02x?}, expected 4c554b53babe")]
15    NotLuks {
16        /// The first six bytes actually found.
17        found: [u8; 6],
18    },
19
20    /// The header version is neither 1 nor 2.
21    #[error("unsupported LUKS version {version} (only 1 and 2 are supported)")]
22    UnsupportedVersion {
23        /// The version field value.
24        version: u16,
25    },
26
27    /// The cipher/mode/hash combination has no validated decrypt path.
28    #[error("unsupported {what}: {value:?}")]
29    Unsupported {
30        /// Which axis is unsupported (cipher, mode, hash).
31        what: &'static str,
32        /// The offending value verbatim.
33        value: String,
34    },
35
36    /// The header is structurally malformed (a field runs past the buffer).
37    #[error("malformed LUKS header: {what} (need {need} bytes, have {got})")]
38    MalformedHeader {
39        /// What was being read.
40        what: &'static str,
41        /// Bytes needed.
42        need: usize,
43        /// Bytes available.
44        got: usize,
45    },
46
47    /// No keyslot could be unlocked with the supplied passphrase, or the derived
48    /// master key failed the mk-digest check (wrong passphrase).
49    #[error("authentication failed: no keyslot matched the passphrase")]
50    AuthenticationFailed,
51
52    /// The container carries no active (enabled) keyslot.
53    #[error("no active keyslot in the LUKS header")]
54    NoActiveKeyslot,
55
56    /// An I/O error reading the container.
57    #[error("I/O error: {0}")]
58    Io(#[from] io::Error),
59}