dns_stamp_parser/
error.rs

1use base64::DecodeError as Base64Error;
2use std::{net::AddrParseError, num::ParseIntError, str::Utf8Error};
3use thiserror::Error;
4
5/// Result for encoding
6pub type EncodeResult<T> = Result<T, EncodeError>;
7
8/// Result for decoding
9pub type DecodeResult<T> = Result<T, DecodeError>;
10
11/// This enum represent all decode errors.
12#[derive(Error, Debug, PartialEq, Eq)]
13pub enum DecodeError {
14    /// This error occurs if the base64 string could not be decoded.
15    #[error("error parsing base 64")]
16    Base64Error(#[from] Base64Error),
17    /// This error occurs if there is not enough bytes.
18    #[error("ran out of bytes to parse")]
19    NotEnoughBytes,
20    /// This error occurs if there is too many bytes.
21    #[error("input too large")]
22    TooManyBytes,
23    /// This error occurs if a string could not be decoded.
24    #[error("string could not be decoded with utf-8")]
25    Utf8Error(#[from] Utf8Error),
26    /// This error occurs if the address could not be decoded.
27    #[error("failed to parse address")]
28    AddrParseError(#[from] AddrParseError),
29    /// This error occurs if the IPv6 address does not have the closing bracket ']'.
30    #[error("missing closing bracket for IPv6")]
31    AddrParseIpv6ClosingBracket,
32    /// This error occurs if an address is missing.
33    #[error("address missing")]
34    MissingAddr,
35    /// This error occurs if the length of an array has not the expected value.
36    #[error("length of array not what was expected")]
37    Len,
38    /// This error occurs if the a integer could not be parsed.
39    /// For example when a port decoded.
40    #[error("failed to parse int value")]
41    ParseIntError(#[from] ParseIntError),
42    /// This error occurs if the regex `DNS_STAMP_REGEX` is not matched.
43    #[error("input is invalid {cause:?}")]
44    InvalidInput {
45        /// cause of the invalid input
46        cause: String,
47    },
48    /// This error occurs if the type is unknown.
49    #[error("unknown type")]
50    UnknownType(u8),
51}
52
53/// This enum represent all encode errors.
54#[derive(Error, Debug, PartialEq, Eq)]
55pub enum EncodeError {
56    /// This error occurs if there is too many bytes to encode.
57    #[error("input too large")]
58    TooManyBytes,
59    /// This error occurs if the array is empty.
60    #[error("array is empty")]
61    EmptyArray,
62}