Skip to main content

wimsey_httpsig/
error.rs

1//! Error type for HTTP Message Signature creation and verification.
2
3/// An error returned while signing or verifying an HTTP message signature.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum HttpSigError {
7    /// A covered component referenced a header field not present in the message.
8    #[error("covered component `{0}` is not present in the message")]
9    MissingComponent(String),
10    /// A component identifier is not supported by this crate.
11    #[error("unsupported component identifier `{0}`")]
12    UnsupportedComponent(String),
13    /// A component value contained a bare CR or LF, which would corrupt the
14    /// signature base.
15    #[error("component `{0}` has a value containing CR or LF")]
16    InvalidComponentValue(String),
17    /// A component required by the verifier was not covered by the signature.
18    #[error("required component `{0}` is not covered by the signature")]
19    MissingRequiredComponent(String),
20    /// The signature's `alg` parameter was present but not `ed25519`.
21    #[error("unexpected algorithm `{found}`, expected `ed25519`")]
22    UnsupportedAlg {
23        /// The `alg` value that was found.
24        found: String,
25    },
26    /// The signature's `expires` is before its `created`.
27    #[error("signature `expires` precedes `created`")]
28    InvalidTimeWindow,
29    /// The signature is older than the verifier's `max_age`.
30    #[error("signature is older than the allowed maximum age")]
31    TooOld,
32    /// The `Signature-Input` or `Signature` field value could not be parsed.
33    #[error("could not parse structured field: {0}")]
34    Parse(String),
35    /// The `Signature-Input` and `Signature` used different labels, or the
36    /// requested label was absent.
37    #[error("signature label mismatch")]
38    LabelMismatch,
39    /// The signature byte sequence was not valid Base64 or not 64 bytes.
40    #[error("malformed signature")]
41    MalformedSignature,
42    /// The signature did not verify against the supplied key.
43    #[error("signature verification failed")]
44    InvalidSignature,
45    /// The signature's `expires` parameter is in the past.
46    #[error("signature has expired")]
47    Expired,
48    /// The signature's `created` parameter is in the future.
49    #[error("signature created in the future")]
50    CreatedInFuture,
51    /// The WIMSE profile requires a signature parameter that is absent.
52    #[error("the WIMSE profile requires the `{0}` signature parameter")]
53    MissingParameter(&'static str),
54    /// The WIMSE profile forbids a signature parameter that is present.
55    #[error("the WIMSE profile forbids the `{0}` signature parameter")]
56    ForbiddenParameter(&'static str),
57    /// The signature's `tag` is not the WIMSE workload-to-workload tag.
58    #[error("unexpected signature tag `{found}`, expected `wimse-workload-to-workload`")]
59    WrongTag {
60        /// The `tag` value that was found.
61        found: String,
62    },
63    /// The signature's `wimse-aud` did not match the audience the verifier
64    /// expected — the signature was minted for a different service.
65    #[error("audience mismatch")]
66    AudienceMismatch,
67    /// A signed response carried back a `wimse-req-nonce` that is not the nonce
68    /// the client sent, so the response answers some other request.
69    #[error("the response's `wimse-req-nonce` does not match the request's nonce")]
70    RequestNonceMismatch,
71}