Kea  1.9.9-git
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 
14 #include <exceptions/exceptions.h>
15 
16 #include <dns/rcode.h>
17 #include <dns/tsigerror.h>
18 
19 namespace isc {
20 namespace dns {
21 namespace {
22 const char* const tsigerror_text[] = {
23  "BADSIG",
24  "BADKEY",
25  "BADTIME",
26  "BADMODE",
27  "BADNAME",
28  "BADALG",
29  "BADTRUNC"
30 };
31 }
32 
33 TSIGError::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 
39 std::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 
50 Rcode
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 
61 std::ostream&
62 operator<<(std::ostream& os, const TSIGError& error) {
63  return (os << error.toText());
64 }
65 } // namespace dns
66 } // namespace isc
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
Rcode toRcode() const
Convert the TSIGError to a Rcode.
Definition: tsigerror.cc:51
DNS Response Codes (RCODEs) class.
Definition: rcode.h:40
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-dhcp-ddns.
uint16_t code_
TSIG errors.
Definition: tsigerror.h:22
TSIGError(uint16_t error_code)
Constructor from the code value.
Definition: tsigerror.h:52
std::string toText() const
Convert the TSIGError to a string.
Definition: tsigerror.cc:40
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static const Rcode & NOTAUTH()
A constant object for the NOTAUTH Rcode (see Rcode::NOTAUTH_CODE).
Definition: rcode.h:274
static const Rcode & SERVFAIL()
A constant object for the SERVFAIL Rcode (see Rcode::SERVFAIL_CODE).
Definition: rcode.h:232