1use crate::components::values::Value;
2
3#[derive(Debug, thiserror::Error)]
4pub enum SignatureError {
5 #[error("`Signature` for the specified Label(`{0}`) is missing.")]
6 NotExist(String),
7 #[error("`Signature` does not exist in header.")]
8 NotExistInHeader,
9 #[error("`Signature` is not a valid `Dictionary`. {0}")]
10 InvalidFormat(#[from] InvalidFormat),
11}
12
13#[derive(Debug, thiserror::Error)]
14pub enum SignatureInputError {
15 #[error("`Signature-Input` does not exist in header.")]
16 NotExistInHeader,
17 #[error(transparent)]
18 InvalidDataFormat(#[from] InvalidFormat),
19}
20
21#[derive(Debug, thiserror::Error)]
22pub enum SignatureParamsError {
23 #[error(transparent)]
24 InvalidHeaderName(#[from] http::Error),
25 #[error(transparent)]
26 InvalidParameter(#[from] InvalidSerializer),
27}
28
29#[derive(Debug, thiserror::Error)]
30pub enum InvalidFormat {
31 #[error("Type `Dictionary` was expected. {0}")]
32 Dictionary(sfv::Error),
33 #[error("Type `InnerList` was expected")]
34 InnerList,
35 #[error("Type `Integer` was expected. {0}")]
36 Integer(sfv::Error),
37 #[error("Type `String` was expected.")]
38 String,
39 #[error(transparent)]
40 HeaderName(http::Error),
41 #[error("Type `ByteSequence` was expected.")]
42 ByteSequence,
43 #[error(transparent)]
44 DerivedComponent(#[from] InvalidDerivedComponent),
45}
46
47#[derive(Debug, thiserror::Error)]
48pub enum InvalidSerializer {
49 #[error("{0} is duplicated. Parameter keys must always be unique.")]
50 Duplicated(String),
51
52 #[error("`{interrogator}` does not correspond to {reject}.")]
53 Incompatible {
54 interrogator: &'static str,
55 reject: String,
56 },
57}
58
59#[derive(Debug, thiserror::Error)]
60pub enum SerializeError {
61 #[error("`{0:?}` is not a valid ASCII string.")]
62 MustBeASCIIString(Value),
63 #[error(transparent)]
64 SfvSerialize(#[from] sfv::Error),
65 #[error("{param_type} parameter does not support `{current_type}`.")]
66 InvalidSerializableValue {
67 param_type: String,
68 current_type: &'static str,
69 },
70 #[error("Entry with the specified key=`{0}` does not exist.")]
71 EntryNotExistsInDictionary(String),
72 #[error("Cannot be parsed as SFV format.")]
73 FailedParseToSfv,
74 #[error(transparent)]
75 InvalidFormat(#[from] InvalidFormat),
76}
77
78#[derive(Debug, thiserror::Error)]
79#[error("Invalid derived component.")]
80pub struct InvalidDerivedComponent;
81
82#[derive(Debug, thiserror::Error)]
83#[error("invalid component parameter: {0}={1:?}")]
84pub struct InvalidComponentParameter(pub sfv::Key, pub sfv::BareItem);
85
86#[derive(Debug, thiserror::Error)]
87pub enum HttpComponentError {
88 #[error("Incorrect data type. expect: {expect}")]
89 InvalidDataType { expect: &'static str },
90 #[error(transparent)]
91 FailedSerializeValue(#[from] SerializeError),
92 #[error("Necessary requirement have not been met. {reason}")]
93 UnmetRequirement { reason: &'static str },
94 #[error("DerivedComponent({0}) not supported.")]
95 UnsupportedComponent(String),
96}
97
98#[derive(Debug, thiserror::Error)]
99pub enum SignError {
100 #[error(transparent)]
101 FailedBuildSignatureBase(#[from] HttpComponentError),
102}
103
104#[derive(Debug, thiserror::Error)]
105pub enum VerificationError {
106 #[error(transparent)]
107 MissingSignature(#[from] SignatureError),
108 #[error("`Signature-Input` for the specified Label(`{0}`) is missing.")]
109 MissingSignatureInput(String),
110 #[error(transparent)]
111 FailedParseSignatureInput(#[from] SignatureInputError),
112 #[error("Failed to decode signature. {0}")]
113 FailedDecodeSignature(#[from] base64::DecodeError),
114 #[error(transparent)]
115 FailedBuildSignatureBase(#[from] HttpComponentError),
116 #[error("Failed to verify signature")]
117 FailedVerifySignature,
118}