Kea 2.7.5
tsigerror.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2015 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#include <config.h>
8
9#include <ostream>
10#include <string>
11
12#include <boost/lexical_cast.hpp>
13
15
16#include <dns/rcode.h>
17#include <dns/tsigerror.h>
18
19namespace isc {
20namespace dns {
21namespace {
22const char* const tsigerror_text[] = {
23 "BADSIG",
24 "BADKEY",
25 "BADTIME",
26 "BADMODE",
27 "BADNAME",
28 "BADALG",
29 "BADTRUNC"
30};
31}
32
33TSIGError::TSIGError(Rcode rcode) : code_(rcode.getCode()) {
34 if (code_ > MAX_RCODE_FOR_TSIGERROR) {
35 isc_throw(OutOfRange, "Invalid RCODE for TSIG Error: " << rcode);
36 }
37}
38
39std::string
41 if (code_ <= MAX_RCODE_FOR_TSIGERROR) {
42 return (Rcode(code_).toText());
43 } else if (code_ <= BAD_TRUNC_CODE) {
44 return (tsigerror_text[code_ - (MAX_RCODE_FOR_TSIGERROR + 1)]);
45 } else {
46 return (boost::lexical_cast<std::string>(code_));
47 }
48}
49
52 if (code_ <= MAX_RCODE_FOR_TSIGERROR) {
53 return (Rcode(code_));
54 }
55 if (code_ > BAD_TRUNC_CODE) {
56 return (Rcode::SERVFAIL());
57 }
58 return (Rcode::NOTAUTH());
59}
60
61std::ostream&
62operator<<(std::ostream& os, const TSIGError& error) {
63 return (os << error.toText());
64}
65} // namespace dns
66} // namespace isc
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
DNS Response Codes (RCODEs) class.
Definition rcode.h:40
static const Rcode & NOTAUTH()
A constant object for the NOTAUTH Rcode (see Rcode::NOTAUTH_CODE).
Definition rcode.h:282
static const Rcode & SERVFAIL()
A constant object for the SERVFAIL Rcode (see Rcode::SERVFAIL_CODE).
Definition rcode.h:240
TSIG errors.
Definition tsigerror.h:22
@ BAD_TRUNC_CODE
22: Bad truncation
Definition tsigerror.h:39
std::string toText() const
Convert the TSIGError to a string.
Definition tsigerror.cc:40
TSIGError(uint16_t error_code)
Constructor from the code value.
Definition tsigerror.h:52
Rcode toRcode() const
Convert the TSIGError to a Rcode.
Definition tsigerror.cc:51
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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.
uint16_t code_