rust_sign/
error.rs

1//! Error types for the rust-sign library.
2
3use thiserror::Error;
4
5/// The main error type for rust-sign operations.
6#[derive(Error, Debug)]
7pub enum SignError {
8    /// Error reading or writing files.
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// Error with JSON serialization/deserialization.
13    #[error("JSON error: {0}")]
14    Json(#[from] serde_json::Error),
15
16    /// Error with base64 encoding/decoding.
17    #[error("Base64 decode error: {0}")]
18    Base64(#[from] base64::DecodeError),
19
20    /// Error with Ed25519 signature operations.
21    #[error("Signature error: {0}")]
22    Signature(#[from] ed25519_dalek::SignatureError),
23
24    /// Invalid key format or length.
25    #[error("Invalid key: {0}")]
26    InvalidKey(String),
27
28    /// Signature verification failed.
29    #[error("Verification failed: {0}")]
30    VerificationFailed(String),
31
32    /// Document hash mismatch.
33    #[error("Hash mismatch: expected {expected}, got {actual}")]
34    HashMismatch { expected: String, actual: String },
35
36    /// No signatures present in document.
37    #[error("No signatures found in document")]
38    NoSignatures,
39
40    /// Invalid signature format or structure.
41    #[error("Invalid signature format: {0}")]
42    InvalidFormat(String),
43}
44
45/// Result type alias for rust-sign operations.
46pub type Result<T> = std::result::Result<T, SignError>;
47