dns_message_parser/decode/
error.rs1use crate::rr::edns::{CookieError, ExtendedDNSErrorExtraTextError};
2use crate::rr::{AddressError, Class, ISDNError, PSDNAddressError, TagError, Type};
3use crate::{Dns, DomainName, DomainNameError, LabelError};
4use hex::FromHexError;
5use std::str::Utf8Error;
6use thiserror::Error;
7
8#[derive(Debug, PartialEq, Error)]
9pub enum DecodeError {
10 #[error("Not enough bytes to decode: got {0} offset {1}")]
11 NotEnoughBytes(usize, usize),
12 #[error("Too many bytes to decode: got {0} parsed {1}")]
13 TooManyBytes(usize, usize),
14 #[error("DNS packet is too big: {0}")]
15 DnsPacketTooBig(usize),
16 #[error("Could not decode Opcode: {0}")]
17 Opcode(u8),
18 #[error("Z bit is not zero: {0}")]
19 ZNotZeroes(u8),
20 #[error("Could not decode RCode: {0}")]
21 RCode(u8),
22 #[error("Could not decode Type: {0}")]
23 Type(u16),
24 #[error("Could not decode Class: {0}")]
25 Class(u16),
26 #[error("Could not decode QType: {0}")]
27 QType(u16),
28 #[error("Could not decode QClass: {0}")]
29 QClass(u16),
30 #[error("Could not decode string as UTF-8: {0}")]
31 Utf8Error(#[from] Utf8Error),
32 #[error("Could not decode label: {0}")]
33 LabelError(#[from] LabelError),
34 #[error("Could not decode domain name: {0}")]
35 DomainNameError(#[from] DomainNameError),
36 #[error("Decode of type {0} is not yet implemented")]
37 NotYetImplemented(Type),
38 #[error("Could not decode hex string: {0}")]
39 FromHexError(#[from] FromHexError),
40 #[error("Offset is not zero: {0}")]
41 Offset(usize),
42 #[error("Class is not IN for A record: {0}")]
43 AClass(Class),
44 #[error("Class is not IN for WKS record: {0}")]
45 WKSClass(Class),
46 #[error("The RData of the TXT is empty")]
47 TXTEmpty,
48 #[error("Could not decode AFSDBSubtype: {0}")]
49 AFSDBSubtype(u16),
50 #[error("Could not decode PSDN address: {0}")]
51 PSDNAddressError(#[from] PSDNAddressError),
52 #[error("Could not decode ISDN: {0}")]
53 ISDNError(#[from] ISDNError),
54 #[error("Could not decode GPOS")]
55 GPOS,
56 #[error("Class is not IN for AAAA record: {0}")]
57 AAAAClass(Class),
58 #[error("Domain name is not root: {0}")]
59 OPTDomainName(DomainName),
60 #[error("OPT header bits is not zero: {0}")]
61 OPTZero(u8),
62 #[error("Could not decode ENDSOptionCode: {0}")]
63 EDNSOptionCode(u16),
64 #[error("Could not decode Address: {0}")]
65 AddressError(#[from] AddressError),
66 #[error("Class is not IN for APL record: {0}")]
67 APLClass(Class),
68 #[error("Could not decode Cookie: {0}")]
69 CookieError(#[from] CookieError),
70 #[error("Could not decode AddressNumber: {0}")]
71 EcsAddressNumber(u16),
72 #[error("Could not decode EcsAddressNumber: {0}")]
73 ExtendedDNSErrorCodes(u16),
74 #[error("Could not decode ExtendedDNSErrorExtraText: {0}")]
75 ExtendedDNSErrorExtraTextError(#[from] ExtendedDNSErrorExtraTextError),
76 #[error("The IPv4 Address is too big: {0}")]
77 EcsTooBigIpv4Address(usize),
78 #[error("The IPv6 Address is too big: {0}")]
79 EcsTooBigIpv6Address(usize),
80 #[error("The cookie length is not 8 or between 16 and 40 bytes: {0}")]
81 CookieLength(usize),
82 #[error("Could not decode SSHFPAlgorithm: {0}")]
83 SSHFPAlgorithm(u8),
84 #[error("Could not decode SSHFPType: {0}")]
85 SSHFPType(u8),
86 #[error("Could not decode AlgorithmType: {0}")]
87 AlgorithmType(u8),
88 #[error("Could not decode DigestType: {0}")]
89 DigestType(u8),
90 #[error("The undefined flags are not zero: {0}")]
91 DNSKEYZeroFlags(u16),
92 #[error("DNSKEY protocol is not equal 3: {0}")]
93 DNSKEYProtocol(u8),
94 #[error("Could not decode the domain name, the because maximum recursion is reached: {0}")]
95 MaxRecursion(usize),
96 #[error("Could not decode the domain name, because an endless recursion was detected: {0}")]
97 EndlessRecursion(u16),
98 #[error("The are remaining bytes, which was not parsed")]
99 RemainingBytes(usize, Dns),
100 #[error("Padding is not zero: {0}")]
101 PaddingZero(u8),
102 #[error("Padding length is too long for u16: {0}")]
103 PaddingLength(usize),
104 #[error("Could not decode Tag: {0}")]
105 TagError(#[from] TagError),
106 #[error("ECH length mismatch. Expected {0} got {1}")]
107 ECHLengthMismatch(usize, usize),
108}