DwmDns-0.1.0
DwmDnsRRDataRRSIG.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/DwmDns/tags/DwmDns-0.1.0/classes/include/DwmDnsRRDataRRSIG.hh 10137 $
3 // @(#) $Id: DwmDnsRRDataRRSIG.hh 10137 2018-01-28 07:25:17Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2018
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMDNSRRDATARRSIG_HH_
43 #define _DWMDNSRRDATARRSIG_HH_
44 
45 #include <cstdint>
46 #include <iostream>
47 #include <string>
48 
49 #include "DwmDnsRRData.hh"
50 
51 namespace Dwm {
52 
53  namespace Dns {
54 
55  //------------------------------------------------------------------------
58  //------------------------------------------------------------------------
60  : public RRData
61  {
62  public:
63  static const uint16_t k_rrtype = 46;
64 
67  static constexpr uint8_t k_algoRSAMD5 = 1;
68  static constexpr uint8_t k_algoDH = 2;
69  static constexpr uint8_t k_algoDSA = 3;
70  static constexpr uint8_t k_algoECC = 4;
71  static constexpr uint8_t k_algoRSASHA1 = 5;
72  static constexpr uint8_t k_algoINDIRECT = 252;
73  static constexpr uint8_t k_algoPRIVATEDNS = 253;
74  static constexpr uint8_t k_algoPRIVATEOID = 254;
76 
77  //----------------------------------------------------------------------
79  //----------------------------------------------------------------------
80  RRDataRRSIG();
81 
82  //----------------------------------------------------------------------
86  //----------------------------------------------------------------------
87  RRDataRRSIG(uint16_t typeCovered, uint8_t algorithm, uint8_t labels,
88  uint32_t originalTTL, uint32_t signatureExpiration,
89  uint32_t signatureInception, uint16_t keyTag,
90  const std::string & signersName,
91  const std::string & signature);
92 
93  //----------------------------------------------------------------------
95  //----------------------------------------------------------------------
96  bool operator == (const RRDataRRSIG & rrsig) const;
97 
98  //----------------------------------------------------------------------
100  //----------------------------------------------------------------------
101  uint16_t TypeCovered() const;
102 
103  //----------------------------------------------------------------------
105  //----------------------------------------------------------------------
106  uint16_t TypeCovered(uint16_t typeCovered);
107 
108  //----------------------------------------------------------------------
110  //----------------------------------------------------------------------
111  uint8_t Algorithm() const;
112 
113  //----------------------------------------------------------------------
115  //----------------------------------------------------------------------
116  uint8_t Algorithm(uint8_t algorithm);
117 
118  //----------------------------------------------------------------------
120  //----------------------------------------------------------------------
121  uint8_t Labels() const;
122 
123  //----------------------------------------------------------------------
125  //----------------------------------------------------------------------
126  uint8_t Labels(uint8_t labels);
127 
128  //----------------------------------------------------------------------
130  //----------------------------------------------------------------------
131  uint32_t OriginalTTL() const;
132 
133  //----------------------------------------------------------------------
135  //----------------------------------------------------------------------
136  uint32_t OriginalTTL(uint32_t originalTTL);
137 
138  //----------------------------------------------------------------------
140  //----------------------------------------------------------------------
141  uint32_t SignatureExpiration() const;
142 
143  //----------------------------------------------------------------------
145  //----------------------------------------------------------------------
146  uint32_t SignatureExpiration(uint32_t signatureExpiration);
147 
148  //----------------------------------------------------------------------
150  //----------------------------------------------------------------------
151  uint32_t SignatureInception() const;
152 
153  //----------------------------------------------------------------------
155  //----------------------------------------------------------------------
156  uint32_t SignatureInception(uint32_t signatureInception);
157 
158  //----------------------------------------------------------------------
160  //----------------------------------------------------------------------
161  uint16_t KeyTag() const;
162 
163  //----------------------------------------------------------------------
165  //----------------------------------------------------------------------
166  uint16_t KeyTag(uint16_t keyTag);
167 
168  //----------------------------------------------------------------------
170  //----------------------------------------------------------------------
171  const std::string & SignersName() const;
172 
173  //----------------------------------------------------------------------
175  //----------------------------------------------------------------------
176  const std::string & SignersName(const std::string & signersName);
177 
178  //----------------------------------------------------------------------
180  //----------------------------------------------------------------------
181  const std::string & Signature() const;
182 
183  //----------------------------------------------------------------------
185  //----------------------------------------------------------------------
186  const std::string & Signature(const std::string & signature);
187 
188  //----------------------------------------------------------------------
194  //----------------------------------------------------------------------
195  uint8_t *Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen,
196  LabelPositions & lps) const;
197 
198  //----------------------------------------------------------------------
204  //----------------------------------------------------------------------
205  const uint8_t *Decode(const uint8_t *pkt, const uint8_t *ptr,
206  uint16_t pktlen, uint16_t rdlen);
207 
208  //----------------------------------------------------------------------
211  //----------------------------------------------------------------------
212  friend std::ostream & operator << (std::ostream & os,
213  const RRDataRRSIG & rrsig);
214 
215  //----------------------------------------------------------------------
219  //----------------------------------------------------------------------
220  static std::string AlgorithmName(uint8_t algo);
221 
222  private:
223  typedef struct __attribute__((packed)) {
224  uint16_t typeCovered;
225  uint8_t algorithm;
226  uint8_t labels;
227  uint32_t originalTTL;
228  uint32_t signatureExpiration;
229  uint32_t signatureInception;
230  uint16_t keyTag;
231  } fixed_data_t;
232 
233  fixed_data_t _fixedData;
234  std::string _signersName;
235  std::string _signature;
236 
237  static fixed_data_t ToNetworkByteOrder(const fixed_data_t *data);
238  static fixed_data_t ToHostByteOrder(const fixed_data_t *data);
239  };
240 
241  } // namespace Dns
242 
243 } // namespace Dwm
244 
245 #endif // _DWMDNSRRDATARRSIG_HH_
uint32_t SignatureInception() const
Returns the contained signature inception.
bool operator==(const RRDataRRSIG &rrsig) const
Equal-to operator, mostly for unit testing.
static constexpr uint8_t k_algoDH
Definition: DwmDnsRRDataRRSIG.hh:68
const uint8_t * Decode(const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen, uint16_t rdlen)
Decodes the RRSIG resource record data from buffer pkt of length pktlen, starting at ptr...
uint8_t * Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen, LabelPositions &lps) const
Encodes the RRSIG resource record data into buffer @ pkt of length pktlen, starting at ptr...
const std::string & Signature() const
Returns the contained signature.
uint8_t Algorithm() const
Returns the contained algorithm.
uint32_t SignatureExpiration() const
Returns the contained signature expiration.
static std::string AlgorithmName(uint8_t algo)
Returns the mnemonic for the given algorithm algo.
static constexpr uint8_t k_algoDSA
Definition: DwmDnsRRDataRRSIG.hh:69
static constexpr uint8_t k_algoPRIVATEDNS
Definition: DwmDnsRRDataRRSIG.hh:73
uint16_t TypeCovered() const
Returns the contained type covered.
uint16_t KeyTag() const
Returns the contained key tag.
static constexpr uint8_t k_algoINDIRECT
Definition: DwmDnsRRDataRRSIG.hh:72
uint8_t Labels() const
Returns the contained labels.
static constexpr uint8_t k_algoRSASHA1
Definition: DwmDnsRRDataRRSIG.hh:71
RRDataRRSIG()
Construct with empty signer&#39;s name and signature.
Definition: DwmDnsEtcHosts.hh:60
friend std::ostream & operator<<(std::ostream &os, const RRDataRRSIG &rrsig)
Print the RRSIG resource record data to an ostream in human readable form.
static constexpr uint8_t k_algoRSAMD5
Definition: DwmDnsRRDataRRSIG.hh:67
Dwm::Dns::RRData class definition.
Encapsulates RRSIG resource record data.
Definition: DwmDnsRRDataRRSIG.hh:59
static constexpr uint8_t k_algoPRIVATEOID
Definition: DwmDnsRRDataRRSIG.hh:74
A helper class used when performing label sequence compression.
Definition: DwmDnsLabelPositions.hh:57
uint32_t OriginalTTL() const
Returns the contained original TTL.
static constexpr uint8_t k_algoECC
Definition: DwmDnsRRDataRRSIG.hh:70
Abstract (pure virtual) base for resource record data classes.
Definition: DwmDnsRRData.hh:71
const std::string & SignersName() const
Returns the contained signer&#39;s name.