Skip to main content

hickory_proto/rr/
mod.rs

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
10use core::fmt::{Debug, Display};
11
12use crate::serialize::binary::{BinDecodable, BinDecoder, BinEncodable, DecodeError, Restrict};
13
14pub(crate) mod dns_class;
15pub use dns_class::DNSClass;
16
17pub mod domain;
18pub use domain::{IntoName, Label, Name};
19
20mod lower_name;
21pub use lower_name::LowerName;
22
23pub mod rdata;
24
25pub(crate) mod record;
26pub use record::{Record, RecordRef};
27
28pub(crate) mod record_data;
29pub use record_data::RData;
30
31pub(crate) mod record_type;
32pub use record_type::RecordType;
33
34pub(crate) mod record_type_set;
35pub use record_type_set::RecordTypeSet;
36
37mod rr_key;
38pub use rr_key::RrKey;
39
40mod rr_set;
41#[cfg(feature = "__dnssec")]
42pub use rr_set::RecordsAndRrsigsIter;
43pub use rr_set::{RecordSet, RecordSetParts, RrsetRecords};
44
45pub(crate) mod serial_number;
46pub use serial_number::SerialNumber;
47
48mod tsig;
49#[cfg(feature = "__dnssec")]
50pub use tsig::TSigVerifier;
51pub use tsig::{TSigResponseContext, TSigner};
52
53/// RecordData that is stored in a DNS Record.
54///
55/// 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.
56pub trait RecordData: Clone + Sized + PartialEq + Eq + Display + Debug + BinEncodable {
57    /// Attempts to borrow this RecordData from the RData type, if it is not the correct type the original is returned
58    fn try_borrow(data: &RData) -> Option<&Self>;
59
60    /// Get the associated RecordType for the RecordData
61    fn record_type(&self) -> RecordType;
62
63    /// Converts this RecordData into generic RecordData
64    fn into_rdata(self) -> RData;
65
66    /// RDLENGTH = 0
67    fn is_update(&self) -> bool {
68        false
69    }
70}
71
72pub(crate) trait RecordDataDecodable<'r>: Sized {
73    /// Read the RecordData from the data stream.
74    ///
75    /// * `decoder` - data stream from which the RData will be read
76    /// * `record_type` - specifies the RecordType that has already been read from the stream
77    /// * `length` - the data length that should be read from the stream for this RecordData
78    fn read_data(decoder: &mut BinDecoder<'r>, length: Restrict<u16>) -> Result<Self, DecodeError>;
79}
80
81impl<'r, T> RecordDataDecodable<'r> for T
82where
83    T: 'r + BinDecodable<'r> + Sized,
84{
85    fn read_data(
86        decoder: &mut BinDecoder<'r>,
87        _length: Restrict<u16>,
88    ) -> Result<Self, DecodeError> {
89        T::read(decoder)
90    }
91}