/src/hickory-dns/crates/proto/src/rr/mod.rs
Line | Count | Source |
1 | | // Copyright 2015-2023 Benjamin Fry <benjaminfry@me.com> |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or |
4 | | // https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
5 | | // https://opensource.org/licenses/MIT>, at your option. This file may not be |
6 | | // copied, modified, or distributed except according to those terms. |
7 | | |
8 | | //! Resource record related components, e.g. `Name` aka label, `Record`, `RData`, ... |
9 | | |
10 | | pub mod dns_class; |
11 | | // TODO: rename to sec |
12 | | pub mod domain; |
13 | | mod lower_name; |
14 | | pub mod rdata; |
15 | | pub mod record_data; |
16 | | pub mod record_type; |
17 | | pub(crate) mod record_type_set; |
18 | | pub mod resource; |
19 | | mod rr_key; |
20 | | mod rr_set; |
21 | | pub mod serial_number; |
22 | | |
23 | | use core::fmt::{Debug, Display}; |
24 | | |
25 | | use crate::{ |
26 | | error::ProtoResult, |
27 | | serialize::binary::{BinDecodable, BinDecoder, BinEncodable, Restrict}, |
28 | | }; |
29 | | |
30 | | pub use self::dns_class::DNSClass; |
31 | | pub use self::domain::{IntoName, Name}; |
32 | | pub use self::record_data::RData; |
33 | | pub use self::record_type::RecordType; |
34 | | pub(crate) use self::record_type_set::RecordTypeSet; |
35 | | pub use self::resource::Record; |
36 | | pub use self::rr_set::RecordSet; |
37 | | pub use self::rr_set::RrsetRecords; |
38 | | pub use lower_name::LowerName; |
39 | | pub use rr_key::RrKey; |
40 | | pub use serial_number::SerialNumber; |
41 | | |
42 | | /// RecordData that is stored in a DNS Record. |
43 | | /// |
44 | | /// This trait allows for generic usage of `RecordData` types inside the `Record` type. Specific RecordData types can be used to enforce compile time constraints on a Record. |
45 | | pub trait RecordData: Clone + Sized + PartialEq + Eq + Display + Debug + BinEncodable { |
46 | | /// Attempts to borrow this RecordData from the RData type, if it is not the correct type the original is returned |
47 | | fn try_borrow(data: &RData) -> Option<&Self>; |
48 | | |
49 | | /// Get the associated RecordType for the RecordData |
50 | | fn record_type(&self) -> RecordType; |
51 | | |
52 | | /// Converts this RecordData into generic RecordData |
53 | | fn into_rdata(self) -> RData; |
54 | | |
55 | | /// RDLENGTH = 0 |
56 | 0 | fn is_update(&self) -> bool { |
57 | 0 | false |
58 | 0 | } |
59 | | } |
60 | | |
61 | | pub(crate) trait RecordDataDecodable<'r>: Sized { |
62 | | /// Read the RecordData from the data stream. |
63 | | /// |
64 | | /// * `decoder` - data stream from which the RData will be read |
65 | | /// * `record_type` - specifies the RecordType that has already been read from the stream |
66 | | /// * `length` - the data length that should be read from the stream for this RecordData |
67 | | fn read_data(decoder: &mut BinDecoder<'r>, length: Restrict<u16>) -> ProtoResult<Self>; |
68 | | } |
69 | | |
70 | | impl<'r, T> RecordDataDecodable<'r> for T |
71 | | where |
72 | | T: 'r + BinDecodable<'r> + Sized, |
73 | | { |
74 | 14.8k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { |
75 | 14.8k | T::read(decoder) |
76 | 14.8k | } <hickory_proto::rr::rdata::hinfo::HINFO as hickory_proto::rr::RecordDataDecodable>::read_data Line | Count | Source | 74 | 3.17k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { | 75 | 3.17k | T::read(decoder) | 76 | 3.17k | } |
<hickory_proto::rr::rdata::naptr::NAPTR as hickory_proto::rr::RecordDataDecodable>::read_data Line | Count | Source | 74 | 3.67k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { | 75 | 3.67k | T::read(decoder) | 76 | 3.67k | } |
<hickory_proto::rr::rdata::mx::MX as hickory_proto::rr::RecordDataDecodable>::read_data Line | Count | Source | 74 | 2.72k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { | 75 | 2.72k | T::read(decoder) | 76 | 2.72k | } |
<hickory_proto::rr::rdata::srv::SRV as hickory_proto::rr::RecordDataDecodable>::read_data Line | Count | Source | 74 | 2.33k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { | 75 | 2.33k | T::read(decoder) | 76 | 2.33k | } |
<hickory_proto::rr::rdata::soa::SOA as hickory_proto::rr::RecordDataDecodable>::read_data Line | Count | Source | 74 | 2.93k | fn read_data(decoder: &mut BinDecoder<'r>, _length: Restrict<u16>) -> ProtoResult<Self> { | 75 | 2.93k | T::read(decoder) | 76 | 2.93k | } |
|
77 | | } |