DwmDns-0.1.0
DwmDnsRRDataKEY.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/DwmDns/tags/DwmDns-0.1.0/classes/include/DwmDnsRRDataKEY.hh 10129 $
3 // @(#) $Id: DwmDnsRRDataKEY.hh 10129 2018-01-27 04:20:26Z 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 _DWMDNSRRDATAKEY_HH_
43 #define _DWMDNSRRDATAKEY_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  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  class RRDataKEY
63  : public RRData
64  {
65  public:
66  static const uint16_t k_rrtype = 25;
67 
68  static const uint16_t k_flagsACMask = 0xC000;
69  static const uint16_t k_flagsXTMask = 0x1000;
70  static const uint16_t k_flagsNAMTYPEMask = 0x0300;
71  static const uint16_t k_flagsSIGMask = 0x000F;
72 
73  static const uint8_t k_protocolReserved = 0;
74  static const uint8_t k_protocolTLS = 1;
75  static const uint8_t k_protocolEmail = 2;
76  static const uint8_t k_protocolDNSSEC = 3;
77  static const uint8_t k_protocolIPSEC = 4;
78  static const uint8_t k_protocolAll = 255;
79 
80  static const uint8_t k_algorithmReserved = 0;
81  static const uint8_t k_algorithmRSA_MD5 = 1;
82  static const uint8_t k_algorithmDiffieHellman = 2;
83  static const uint8_t k_algorithmDSA = 3;
84 
85  //----------------------------------------------------------------------
87  //----------------------------------------------------------------------
88  RRDataKEY();
89 
90  //----------------------------------------------------------------------
93  //----------------------------------------------------------------------
94  RRDataKEY(uint16_t flags, uint8_t protocol, uint8_t algorithm,
95  uint16_t moreFlags, const std::string & publicKey);
96 
97  //----------------------------------------------------------------------
99  //----------------------------------------------------------------------
100  bool operator == (const RRDataKEY & key) const;
101 
102  //----------------------------------------------------------------------
104  //----------------------------------------------------------------------
105  uint16_t Flags() const;
106 
107  //----------------------------------------------------------------------
109  //----------------------------------------------------------------------
110  uint16_t Flags(uint16_t flags);
111 
112  //----------------------------------------------------------------------
114  //----------------------------------------------------------------------
115  uint8_t Protocol() const;
116 
117  //----------------------------------------------------------------------
119  //----------------------------------------------------------------------
120  uint8_t Protocol(uint8_t protocol);
121 
122  //----------------------------------------------------------------------
124  //----------------------------------------------------------------------
125  uint8_t Algorithm() const;
126 
127  //----------------------------------------------------------------------
129  //----------------------------------------------------------------------
130  uint8_t Algorithm(uint8_t algorithm);
131 
132  //----------------------------------------------------------------------
134  //----------------------------------------------------------------------
135  uint16_t MoreFlags() const;
136 
137  //----------------------------------------------------------------------
139  //----------------------------------------------------------------------
140  uint16_t MoreFlags(uint16_t moreFlags);
141 
142  //----------------------------------------------------------------------
144  //----------------------------------------------------------------------
145  const std::string & PublicKey() const;
146 
147  //----------------------------------------------------------------------
149  //----------------------------------------------------------------------
150  const std::string & PublicKey(const std::string & publicKey);
151 
152  //----------------------------------------------------------------------
158  //----------------------------------------------------------------------
159  uint8_t *Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen,
160  LabelPositions & lps) const;
161 
162  //----------------------------------------------------------------------
168  //----------------------------------------------------------------------
169  const uint8_t *Decode(const uint8_t *pkt, const uint8_t *ptr,
170  uint16_t pktlen, uint16_t rdlen);
171 
172  //----------------------------------------------------------------------
175  //----------------------------------------------------------------------
176  friend std::ostream & operator << (std::ostream & os,
177  const RRDataKEY & key);
178 
179  private:
180  uint16_t _flags;
181  uint8_t _protocol;
182  uint8_t _algorithm;
183  uint16_t _moreFlags;
184  std::string _publicKey;
185  };
186 
187  } // namespace Dns
188 
189 } // namespace Dwm
190 
191 #endif // _DWMDNSRRDATAKEY_HH_
Encapsulates KEY resource record data.
Definition: DwmDnsRRDataKEY.hh:62
friend std::ostream & operator<<(std::ostream &os, const RRDataKEY &key)
Print the KEY resource record data to an ostream in human readable form.
const uint8_t * Decode(const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen, uint16_t rdlen)
Decodes the KEY resource record data from buffer pkt of length pktlen, starting at ptr...
uint16_t Flags() const
Returns the contained flags.
uint8_t * Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen, LabelPositions &lps) const
Encodes the KEY resource record data into buffer @ pkt of length pktlen, starting at ptr...
const std::string & PublicKey() const
Returns the contained public key.
Definition: DwmDnsEtcHosts.hh:60
bool operator==(const RRDataKEY &key) const
Equal-to operator, mostly for unit testing.
uint8_t Protocol() const
Returns the contained protocol.
uint16_t MoreFlags() const
Returns the contained &#39;more flags&#39;.
RRDataKEY()
Construct with an empty public key.
Dwm::Dns::RRData class definition.
A helper class used when performing label sequence compression.
Definition: DwmDnsLabelPositions.hh:57
uint8_t Algorithm() const
Returns the contained algorithm.
Abstract (pure virtual) base for resource record data classes.
Definition: DwmDnsRRData.hh:71