Skip to main content

floe_rs/
result.rs

1// Copyright 2026 Damir Jelić, Snowflake Inc.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use 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}