bh_status_list/
error.rs

1// Copyright (C) 2020-2025  The Blockhouse Technology Limited (TBTL).
2//
3// This program is free software: you can redistribute it and/or modify it
4// under the terms of the GNU Affero General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or (at your
6// option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
11// License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16use crate::{StatusBits, UriBuf};
17
18/// Error type defining possible Status List related errors.
19#[derive(strum_macros::Display)]
20pub enum Error {
21    /// Error when compressing Status List.
22    #[strum(to_string = "Status List compression error")]
23    Compression,
24
25    /// Error when decompressing Status List.
26    #[strum(to_string = "Status List decompression error")]
27    Decompression,
28
29    /// Error when Status List size is inconsistent with the internal representation.
30    #[strum(to_string = "Status List size is inconsistent with the actual list")]
31    InconsistentSize,
32
33    /// Error when the status doesn't fit in the specified number of bits.
34    #[strum(to_string = "Status {1} does not fit in {0} bits")]
35    StatusTooLarge(StatusBits, u8),
36
37    /// Error when the Status List index is out of bounds.
38    #[strum(to_string = "index={1} is out of bounds (size={0})")]
39    IndexOutOfBounds(usize, usize),
40
41    /// Error when token signing fails.
42    #[strum(to_string = "Unable to sign Status List Token")]
43    TokenSigningFailed,
44
45    /// Error when token parsing fails.
46    #[strum(to_string = "Unable to parse a Status List Token")]
47    TokenParsingFailed,
48
49    /// Error when token signature verification fails.
50    #[strum(to_string = "Unable to verify the signature of the Status List Token")]
51    TokenSignatureVerificationFailed,
52
53    /// Error when the token header `typ` value is invalid.
54    #[strum(to_string = "JWT header `typ` MUST be \"statuslist+jwt\", but is \"{0}\"")]
55    InvalidTokenHeaderTyp(String),
56
57    /// Error when the token `iss` value is invalid.
58    #[strum(to_string = "The `iss` value ({1}) MUST be the same as in the issued VC ({0})")]
59    InvalidTokenIss(UriBuf, UriBuf),
60
61    /// Error when the token `sub` value is invalid.
62    #[strum(to_string = "The `sub` value ({1}) MUST be the same as `uri` in the issued VC ({0})")]
63    InvalidTokenSub(UriBuf, UriBuf),
64
65    /// Error when the token is expired.
66    #[strum(to_string = "Token expired (exp={1}, current_time={0})")]
67    TokenExpired(u64, u64),
68
69    /// Error when the Status List cannot be fetched from URL.
70    #[strum(to_string = "Unable to fetch status from {0}")]
71    UnsuccessfulStatusFetch(UriBuf),
72}
73
74impl bherror::BhError for Error {}
75
76/// Result type alias for the crate.
77pub type Result<T> = bherror::Result<T, Error>;