1use thiserror::Error;
17
18use crate::types::Parameters;
19
20#[derive(Debug, Error)]
21pub enum DecryptionError {
22 #[error("the ciphertext couldn't be decrypted")]
23 Aead(#[from] aead::Error),
24
25 #[error("the Floe header contains an invalid tag")]
26 InvalidHeaderTag,
27
28 #[error("the output buffer has an incorrect length, expected: {expected}, got {got}")]
29 InvalidBuffer { expected: usize, got: usize },
30
31 #[error("the ciphertext has an incorrect length, expected: {expected}, got {got}")]
32 InvalidCiphertextLength { expected: usize, got: usize },
33
34 #[error("we have reached the maximal number of segments the configured AEAD supports ({0})")]
35 MaxSegmentsReached(u64),
36
37 #[error("the segment is too big")]
38 MalformedSegment,
39
40 #[error(
41 "the given header has different Floe parameters compared to what was configured \
42 in the decryptor, expected: {expected:?}, got: {got:?}"
43 )]
44 InvalidParameters { expected: Parameters, got: Parameters },
45}
46
47#[derive(Debug, Error)]
48pub enum EncryptionError {
49 #[error("the ciphertext couldn't be decrypted")]
50 Aead(#[from] aead::Error),
51
52 #[error("we have reached the maximal number of segments the configured AEAD supports ({0})")]
53 MaxSegmentsReached(u64),
54
55 #[error("the output buffer has an incorrect length, expected: {expected}, got {got}")]
56 InvalidBuffer { expected: usize, got: usize },
57
58 #[error("the plaintext has an incorrect length, expected: {expected}, got {got}")]
59 InvalidPlaintextLength { expected: usize, got: usize },
60
61 #[error("the random nonce for the segment couldn't be generated")]
62 NonceGenerationFailed,
63}
64
65#[derive(Debug, Error)]
66pub enum HeaderDecodeError {
67 #[error("the given header has an incorrect length, expected {expected}, got {got}")]
68 InvalidLength { expected: usize, got: usize },
69}
70
71#[derive(Debug, Error)]
72pub enum SegmentDecodeError {
73 #[error(
74 "the given slice is too small to be interpreted as a segment, expected at least {expected} bytes, got {got}"
75 )]
76 InvalidSliceLength { expected: usize, got: usize },
77
78 #[error("the segment is corrupted")]
79 MalformedSegment,
80}