asimov_http/error.rs
1// This is free and unencumbered software released into the public domain.
2
3use alloc::string::String;
4
5/// HTTP integrity construction, parsing, or verification failure.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 /// A Structured Field is malformed or has the wrong semantic type.
9 #[error("invalid integrity field: {0}")]
10 InvalidField(&'static str),
11 /// A field or derived component is unavailable in this message context.
12 #[error("missing HTTP signature component: {0}")]
13 MissingComponent(String),
14 /// A component identifier or its parameters cannot be processed.
15 #[error("invalid HTTP signature component: {0}")]
16 InvalidComponent(String),
17 /// The message context lacks a valid, absolute HTTP(S) target URI.
18 #[error("invalid HTTP signature target URI")]
19 InvalidTargetUri,
20 /// Covered components must be unique, regardless of parameter ordering.
21 #[error("duplicate covered component")]
22 DuplicateComponent,
23 /// Reusing a signature label would make selection ambiguous.
24 #[error("duplicate signature label")]
25 DuplicateLabel,
26 /// SHA-256 was absent, malformed, or did not match the message content.
27 #[error("missing or mismatched SHA-256 content digest")]
28 ContentDigest,
29 /// An algorithm other than Ed25519 was requested or asserted.
30 #[error("only Ed25519 HTTP message signatures are supported")]
31 Algorithm,
32 /// Ed25519 verification failed.
33 #[error("invalid HTTP message signature")]
34 Signature,
35 /// A required profile constraint was not satisfied.
36 #[error("HTTP signature policy rejected the message: {0}")]
37 Policy(&'static str),
38 /// Integrity metadata exceeded the documented parsing limits.
39 #[error("HTTP integrity metadata limit exceeded")]
40 Limit,
41 /// A frame appeared after trailers, or more than one trailer frame appeared.
42 #[error("invalid HTTP body frame order")]
43 FrameOrder,
44 /// Streaming trailers cannot be used with these HTTP semantics.
45 #[error("trailers are unavailable for this message")]
46 TrailersUnavailable,
47 /// OS entropy could not be obtained.
48 #[error("failed to generate signature nonce: {0}")]
49 Random(String),
50 /// The wall clock cannot be represented as a nonnegative UNIX timestamp.
51 #[error("invalid signature clock")]
52 Clock,
53}
54
55impl From<sfv::Error> for Error {
56 fn from(_: sfv::Error) -> Self {
57 Self::InvalidField("structured field syntax")
58 }
59}