Skip to main content

kulfi_id52/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4/// Error when parsing an ID52 string
5#[derive(Debug, Clone)]
6pub struct ParseId52Error {
7    pub input: String,
8    pub reason: String,
9}
10
11impl fmt::Display for ParseId52Error {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        write!(f, "Invalid ID52 '{}': {}", self.input, self.reason)
14    }
15}
16
17impl Error for ParseId52Error {}
18
19/// Error when parsing a secret key from string
20#[derive(Debug, Clone)]
21pub struct ParseSecretKeyError {
22    pub reason: String,
23}
24
25impl fmt::Display for ParseSecretKeyError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        write!(f, "Invalid secret key: {}", self.reason)
28    }
29}
30
31impl Error for ParseSecretKeyError {}
32
33/// Error when creating keys from invalid byte arrays
34#[derive(Debug, Clone)]
35pub struct InvalidKeyBytesError {
36    pub expected: usize,
37    pub got: usize,
38}
39
40impl fmt::Display for InvalidKeyBytesError {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        write!(
43            f,
44            "Invalid key length: expected {} bytes, got {}",
45            self.expected, self.got
46        )
47    }
48}
49
50impl Error for InvalidKeyBytesError {}
51
52/// Error when signature verification fails
53#[derive(Debug, Clone)]
54pub struct SignatureVerificationError;
55
56impl fmt::Display for SignatureVerificationError {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        write!(f, "Signature verification failed")
59    }
60}
61
62impl Error for SignatureVerificationError {}
63
64/// Error when creating signature from invalid bytes
65#[derive(Debug, Clone)]
66pub struct InvalidSignatureBytesError {
67    pub expected: usize,
68    pub got: usize,
69}
70
71impl fmt::Display for InvalidSignatureBytesError {
72    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73        write!(
74            f,
75            "Invalid signature length: expected {} bytes, got {}",
76            self.expected, self.got
77        )
78    }
79}
80
81impl Error for InvalidSignatureBytesError {}