Kea 3.3.3
tsigerror.h
Go to the documentation of this file.
1// Copyright (C) 2011-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef TSIGERROR_H
8#define TSIGERROR_H
9
10#include <dns/rcode.h>
11
12#include <cstdint>
13#include <ostream>
14#include <string>
15
16namespace isc {
17namespace dns {
23class TSIGError {
24public:
42
47
48
53 explicit TSIGError(uint16_t error_code) : code_(error_code) {}
54
66 explicit TSIGError(Rcode rcode);
68
74 uint16_t getCode() const {
75 return (code_);
76 }
77
86 bool equals(const TSIGError& other) const {
87 return (code_ == other.code_);
88 }
89
91 bool operator==(const TSIGError& other) const {
92 return (equals(other));
93 }
94
102 bool nequals(const TSIGError& other) const {
103 return (code_ != other.code_);
104 }
105
107 bool operator!=(const TSIGError& other) const {
108 return (nequals(other));
109 }
110
125 std::string toText() const;
126
141 Rcode toRcode() const;
142
144 static const TSIGError& NOERROR();
145
147 static const TSIGError& FORMERR();
148
150 static const TSIGError& SERVFAIL();
151
153 static const TSIGError& NXDOMAIN();
154
156 static const TSIGError& NOTIMP();
157
159 static const TSIGError& REFUSED();
160
162 static const TSIGError& YXDOMAIN();
163
165 static const TSIGError& YXRRSET();
166
168 static const TSIGError& NXRRSET();
169
171 static const TSIGError& NOTAUTH();
172
174 static const TSIGError& NOTZONE();
175
177 static const TSIGError& RESERVED11();
178
180 static const TSIGError& RESERVED12();
181
183 static const TSIGError& RESERVED13();
184
186 static const TSIGError& RESERVED14();
187
189 static const TSIGError& RESERVED15();
190
193 static const TSIGError& BAD_SIG();
194
197 static const TSIGError& BAD_KEY();
198
201 static const TSIGError& BAD_TIME();
202
205 static const TSIGError& BAD_MODE();
206
209 static const TSIGError& BAD_NAME();
210
213 static const TSIGError& BAD_ALG();
214
217 static const TSIGError& BAD_TRUNC();
218
219private:
220 // This is internally used to specify the maximum possible RCODE value
221 // that can be convertible to TSIGErrors.
222 static const int MAX_RCODE_FOR_TSIGERROR = 15;
223
224 uint16_t code_;
225};
226
227inline const TSIGError&
229 static TSIGError e(Rcode::NOERROR());
230 return (e);
231}
232
233inline const TSIGError&
235 static TSIGError e(Rcode::FORMERR());
236 return (e);
237}
238
239inline const TSIGError&
241 static TSIGError e(Rcode::SERVFAIL());
242 return (e);
243}
244
245inline const TSIGError&
247 static TSIGError e(Rcode::NXDOMAIN());
248 return (e);
249}
250
251inline const TSIGError&
253 static TSIGError e(Rcode::NOTIMP());
254 return (e);
255}
256
257inline const TSIGError&
259 static TSIGError e(Rcode::REFUSED());
260 return (e);
261}
262
263inline const TSIGError&
265 static TSIGError e(Rcode::YXDOMAIN());
266 return (e);
267}
268
269inline const TSIGError&
271 static TSIGError e(Rcode::YXRRSET());
272 return (e);
273}
274
275inline const TSIGError&
277 static TSIGError e(Rcode::NXRRSET());
278 return (e);
279}
280
281inline const TSIGError&
283 static TSIGError e(Rcode::NOTAUTH());
284 return (e);
285}
286
287inline const TSIGError&
289 static TSIGError e(Rcode::NOTZONE());
290 return (e);
291}
292
293inline const TSIGError&
295 static TSIGError e(Rcode::RESERVED11());
296 return (e);
297}
298
299inline const TSIGError&
301 static TSIGError e(Rcode::RESERVED12());
302 return (e);
303}
304
305inline const TSIGError&
307 static TSIGError e(Rcode::RESERVED13());
308 return (e);
309}
310
311inline const TSIGError&
313 static TSIGError e(Rcode::RESERVED14());
314 return (e);
315}
316
317inline const TSIGError&
319 static TSIGError e(Rcode::RESERVED15());
320 return (e);
321}
322
323inline const TSIGError&
325 static TSIGError e(BAD_SIG_CODE);
326 return (e);
327}
328
329inline const TSIGError&
331 static TSIGError e(BAD_KEY_CODE);
332 return (e);
333}
334
335inline const TSIGError&
337 static TSIGError e(BAD_TIME_CODE);
338 return (e);
339}
340
341inline const TSIGError&
343 static TSIGError e(BAD_MODE_CODE);
344 return (e);
345}
346
347inline const TSIGError&
349 static TSIGError e(BAD_NAME_CODE);
350 return (e);
351}
352
353inline const TSIGError&
355 static TSIGError e(BAD_ALG_CODE);
356 return (e);
357}
358
359inline const TSIGError&
361 static TSIGError e(BAD_TRUNC_CODE);
362 return (e);
363}
364
375std::ostream& operator<<(std::ostream& os, const TSIGError& tsig_error);
376}
377}
378
379#endif // TSIGERROR_H
DNS Response Codes (RCODEs) class.
Definition rcode.h:39
static const Rcode & RESERVED13()
A constant object for a reserved (code 13) Rcode.
Definition rcode.h:305
static const Rcode & NOERROR()
A constant object for the NOERROR Rcode (see Rcode::NOERROR_CODE).
Definition rcode.h:227
static const Rcode & RESERVED11()
A constant object for a reserved (code 11) Rcode.
Definition rcode.h:293
static const Rcode & FORMERR()
A constant object for the FORMERR Rcode (see Rcode::FORMERR_CODE).
Definition rcode.h:233
static const Rcode & RESERVED14()
A constant object for a reserved (code 14) Rcode.
Definition rcode.h:311
static const Rcode & NXRRSET()
A constant object for the NXRRSET Rcode (see Rcode::NXRRSET_CODE).
Definition rcode.h:275
static const Rcode & NXDOMAIN()
A constant object for the NXDOMAIN Rcode (see Rcode::NXDOMAIN_CODE).
Definition rcode.h:245
static const Rcode & NOTIMP()
A constant object for the NOTIMP Rcode (see Rcode::NOTIMP_CODE).
Definition rcode.h:251
static const Rcode & YXRRSET()
A constant object for the YXRRSET Rcode (see Rcode::YXRRSET_CODE).
Definition rcode.h:269
static const Rcode & RESERVED12()
A constant object for a reserved (code 12) Rcode.
Definition rcode.h:299
static const Rcode & RESERVED15()
A constant object for a reserved (code 15) Rcode.
Definition rcode.h:317
static const Rcode & NOTAUTH()
A constant object for the NOTAUTH Rcode (see Rcode::NOTAUTH_CODE).
Definition rcode.h:281
static const Rcode & SERVFAIL()
A constant object for the SERVFAIL Rcode (see Rcode::SERVFAIL_CODE).
Definition rcode.h:239
static const Rcode & NOTZONE()
A constant object for the NOTZONE Rcode (see Rcode::NOTZONE_CODE).
Definition rcode.h:287
static const Rcode & REFUSED()
A constant object for the REFUSED Rcode (see Rcode::REFUSED_CODE).
Definition rcode.h:257
static const Rcode & YXDOMAIN()
A constant object for the YXDOMAIN Rcode (see Rcode::YXDOMAIN_CODE).
Definition rcode.h:263
TSIG errors.
Definition tsigerror.h:23
CodeValue
Constants for pre-defined TSIG error values.
Definition tsigerror.h:33
@ BAD_ALG_CODE
21: TKEY algorithm not supported
Definition tsigerror.h:39
@ BAD_NAME_CODE
20: Duplicate TKEY name
Definition tsigerror.h:38
@ BAD_KEY_CODE
17: TSIG key is not recognized
Definition tsigerror.h:35
@ BAD_TRUNC_CODE
22: Bad truncation
Definition tsigerror.h:40
@ BAD_TIME_CODE
18: Current time and time signed are too different
Definition tsigerror.h:36
@ BAD_SIG_CODE
16: TSIG verification failure
Definition tsigerror.h:34
@ BAD_MODE_CODE
19: Bad TKEY mode
Definition tsigerror.h:37
bool operator==(const TSIGError &other) const
Same as equals().
Definition tsigerror.h:91
static const TSIGError & SERVFAIL()
A constant TSIG error object derived from Rcode::SERVFAIL().
Definition tsigerror.h:240
bool nequals(const TSIGError &other) const
Return true iff two TSIGError objects are not equal.
Definition tsigerror.h:102
static const TSIGError & RESERVED14()
A constant TSIG error object derived from Rcode::RESERVED14().
Definition tsigerror.h:312
static const TSIGError & YXRRSET()
A constant TSIG error object derived from Rcode::YXRRSET().
Definition tsigerror.h:270
static const TSIGError & BAD_ALG()
A constant TSIG error object for the BADALG code (see TSIGError::BAD_ALG_CODE).
Definition tsigerror.h:354
bool operator!=(const TSIGError &other) const
Same as nequals().
Definition tsigerror.h:107
static const TSIGError & YXDOMAIN()
A constant TSIG error object derived from Rcode::YXDOMAIN().
Definition tsigerror.h:264
static const TSIGError & NOTZONE()
A constant TSIG error object derived from Rcode::NOTZONE().
Definition tsigerror.h:288
std::string toText() const
Convert the TSIGError to a string.
Definition tsigerror.cc:40
static const TSIGError & BAD_NAME()
A constant TSIG error object for the BADNAME code (see TSIGError::BAD_NAME_CODE).
Definition tsigerror.h:348
static const TSIGError & NXRRSET()
A constant TSIG error object derived from Rcode::NXRRSET().
Definition tsigerror.h:276
static const TSIGError & NOTIMP()
A constant TSIG error object derived from Rcode::NOTIMP().
Definition tsigerror.h:252
static const TSIGError & REFUSED()
A constant TSIG error object derived from Rcode::REFUSED().
Definition tsigerror.h:258
TSIGError(uint16_t error_code)
Constructor from the code value.
Definition tsigerror.h:53
static const TSIGError & RESERVED11()
A constant TSIG error object derived from Rcode::RESERVED11().
Definition tsigerror.h:294
static const TSIGError & RESERVED15()
A constant TSIG error object derived from Rcode::RESERVED15().
Definition tsigerror.h:318
static const TSIGError & BAD_SIG()
A constant TSIG error object for the BADSIG code (see TSIGError::BAD_SIG_CODE).
Definition tsigerror.h:324
static const TSIGError & BAD_MODE()
A constant TSIG error object for the BADMODE code (see TSIGError::BAD_MODE_CODE).
Definition tsigerror.h:342
static const TSIGError & BAD_KEY()
A constant TSIG error object for the BADKEY code (see TSIGError::BAD_KEY_CODE).
Definition tsigerror.h:330
static const TSIGError & BAD_TIME()
A constant TSIG error object for the BADTIME code (see TSIGError::BAD_TIME_CODE).
Definition tsigerror.h:336
static const TSIGError & NXDOMAIN()
A constant TSIG error object derived from Rcode::NXDOMAIN().
Definition tsigerror.h:246
uint16_t getCode() const
Returns the TSIGCode error code value.
Definition tsigerror.h:74
static const TSIGError & RESERVED13()
A constant TSIG error object derived from Rcode::RESERVED13().
Definition tsigerror.h:306
static const TSIGError & NOTAUTH()
A constant TSIG error object derived from Rcode::NOTAUTH().
Definition tsigerror.h:282
static const TSIGError & NOERROR()
A constant TSIG error object derived from Rcode::NOERROR().
Definition tsigerror.h:228
static const TSIGError & BAD_TRUNC()
A constant TSIG error object for the BADTRUNC code (see TSIGError::BAD_TRUNC_CODE).
Definition tsigerror.h:360
static const TSIGError & FORMERR()
A constant TSIG error object derived from Rcode::FORMERR().
Definition tsigerror.h:234
static const TSIGError & RESERVED12()
A constant TSIG error object derived from Rcode::RESERVED12().
Definition tsigerror.h:300
bool equals(const TSIGError &other) const
Return true iff two TSIGError objects are equal.
Definition tsigerror.h:86
Rcode toRcode() const
Convert the TSIGError to a Rcode.
Definition tsigerror.cc:51
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
Defines the logger used by the top-level component of kea-lfc.