others.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. use std::fmt;
  2. /// A number representing a record type dog can’t deal with.
  3. #[derive(PartialEq, Debug, Copy, Clone)]
  4. pub enum UnknownQtype {
  5. /// An rtype number that dog is aware of, but does not know how to parse.
  6. HeardOf(&'static str),
  7. /// A completely unknown rtype number.
  8. UnheardOf(u16),
  9. }
  10. impl From<u16> for UnknownQtype {
  11. fn from(qtype: u16) -> Self {
  12. match TYPES.iter().find(|t| t.1 == qtype) {
  13. Some(tuple) => Self::HeardOf(tuple.0),
  14. None => Self::UnheardOf(qtype),
  15. }
  16. }
  17. }
  18. impl fmt::Display for UnknownQtype {
  19. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  20. match self {
  21. Self::HeardOf(name) => write!(f, "{}", name),
  22. Self::UnheardOf(num) => write!(f, "{}", num),
  23. }
  24. }
  25. }
  26. /// Looks up a record type for a name dog knows about, but still doesn’t know
  27. /// how to parse.
  28. pub fn find_other_qtype_number(name: &str) -> Option<u16> {
  29. TYPES.iter().find(|t| t.0 == name).map(|t| t.1)
  30. }
  31. /// Mapping of record type names to their assigned numbers.
  32. static TYPES: &[(&str, u16)] = &[
  33. ("AFSDB", 18),
  34. ("ANY", 255),
  35. ("APL", 42),
  36. ("AXFR", 252),
  37. ("CDNSKEY", 60),
  38. ("CDS", 59),
  39. ("CERT", 37),
  40. ("CSYNC", 62),
  41. ("DHCID", 49),
  42. ("DLV", 32769),
  43. ("DNAME", 39),
  44. ("DNSKEEYE", 48),
  45. ("DS", 43),
  46. ("HINFO", 13),
  47. ("HIP", 55),
  48. ("IPSECKEY", 45),
  49. ("IXFR", 251),
  50. ("KEY", 25),
  51. ("KX", 36),
  52. ("LOC", 29),
  53. ("NAPTR", 35),
  54. ("NSEC", 47),
  55. ("NSEC3", 50),
  56. ("NSEC3PARAM", 51),
  57. ("OPENPGPKEY", 61),
  58. ("RRSIG", 46),
  59. ("RP", 17),
  60. ("SIG", 24),
  61. ("SMIMEA", 53),
  62. ("SSHFP", 44),
  63. ("TA", 32768),
  64. ("TKEY", 249),
  65. ("TLSA", 52),
  66. ("TSIG", 250),
  67. ("URI", 256),
  68. ];