Skip to main content

coz_rs/
error.rs

1//! Error types for the Coz library.
2
3use thiserror::Error;
4
5/// The main error type for Coz operations.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Base64 decoding failed.
9    #[error("invalid base64: {0}")]
10    Base64(#[from] base64ct::Error),
11
12    /// JSON serialization or deserialization failed.
13    #[error("JSON error: {0}")]
14    Json(#[from] serde_json::Error),
15
16    /// Signature verification failed.
17    #[error("signature verification failed")]
18    SignatureVerification,
19
20    /// Invalid signature format or encoding.
21    #[error("invalid signature: {0}")]
22    InvalidSignature(String),
23
24    /// Invalid key format or encoding.
25    #[error("invalid key: {0}")]
26    InvalidKey(String),
27
28    /// Thumbprint mismatch.
29    #[error("thumbprint mismatch: expected {expected}, got {actual}")]
30    ThumbprintMismatch {
31        /// Expected thumbprint.
32        expected: String,
33        /// Actual thumbprint.
34        actual: String,
35    },
36
37    /// Algorithm mismatch between key and payload.
38    #[error("algorithm mismatch: key uses {key_alg}, payload specifies {pay_alg}")]
39    AlgorithmMismatch {
40        /// Algorithm from the key.
41        key_alg: &'static str,
42        /// Algorithm from the payload.
43        pay_alg: String,
44    },
45
46    /// Revoke payload exceeds maximum size.
47    #[error("revoke payload size {size} exceeds maximum {max}")]
48    RevokeTooLarge {
49        /// Actual size of the payload.
50        size: usize,
51        /// Maximum allowed size.
52        max: usize,
53    },
54
55    /// Invalid timestamp value.
56    #[error("invalid timestamp: {0}")]
57    InvalidTimestamp(String),
58
59    /// Missing required field.
60    #[error("missing required field: {0}")]
61    MissingField(&'static str),
62
63    /// Canonicalization failed.
64    #[error("canonicalization error: {0}")]
65    Canonicalization(String),
66}
67
68/// Result type alias for Coz operations.
69pub type Result<T> = std::result::Result<T, Error>;