]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3208] clean up code
authorRazvan Becheriu <razvan@isc.org>
Fri, 8 Mar 2024 18:19:05 +0000 (20:19 +0200)
committerRazvan Becheriu <razvan@isc.org>
Sat, 9 Mar 2024 06:43:56 +0000 (08:43 +0200)
25 files changed:
src/lib/dns/char_string.cc
src/lib/dns/labelsequence.cc
src/lib/dns/master_lexer.cc
src/lib/dns/master_lexer.h
src/lib/dns/master_lexer_inputsource.cc
src/lib/dns/master_loader.cc
src/lib/dns/message.h
src/lib/dns/messagerenderer.cc
src/lib/dns/rdata.cc
src/lib/dns/rdataclass.cc
src/lib/dns/rrclass.h
src/lib/dns/rrparamregistry.cc
src/lib/dns/rrset.cc
src/lib/dns/rrttl.cc
src/lib/dns/rrtype.h
src/lib/dns/tests/message_unittest.cc
src/lib/dns/tests/rdata_char_string_unittest.cc
src/lib/dns/tests/rdata_opt_unittest.cc
src/lib/dns/tests/rdata_soa_unittest.cc
src/lib/dns/tests/rdata_txt_like_unittest.cc
src/lib/dns/tests/rdata_unittest.h
src/lib/dns/tests/rrclass_unittest.cc
src/lib/dns/tests/rrtype_unittest.cc
src/lib/dns/tests/tsig_unittest.cc
src/lib/dns/tsig.cc

index c28d2047c530da13bf5224226e2104a9f4e2e917..25cb1f180fbfce73bb2bd345e54985752247f46b 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <cassert>
 #include <cctype>
 #include <cstring>
 #include <vector>
@@ -66,7 +65,10 @@ stringToCharString(const MasterToken::StringRegion& str_region,
         int c = (*s & 0xff);
         if (escape && std::isdigit(c) != 0) {
             c = decimalToNumber(s, s_end);
-            assert(n >= 3);
+            // decimalToNumber() already throws if (s_end - s) is less
+            // than 3. 'n' is an unsigned type (size_t) and can underflow.
+            // 'n' and 's' are also updated by 1 in the for statement's
+            // expression, so we update them by 2 instead of 3 here.
             n -= 2;
             s += 2;
         } else if (!escape && c == '\\') {
@@ -98,10 +100,7 @@ stringToCharStringData(const MasterToken::StringRegion& str_region,
         if (escape && std::isdigit(c) != 0) {
             c = decimalToNumber(s, s_end);
             // decimalToNumber() already throws if (s_end - s) is less
-            // than 3, so the following assertion is unnecessary. But we
-            // assert it anyway. 'n' is an unsigned type (size_t) and
-            // can underflow.
-            assert(n >= 3);
+            // than 3. 'n' is an unsigned type (size_t) and can underflow.
             // 'n' and 's' are also updated by 1 in the for statement's
             // expression, so we update them by 2 instead of 3 here.
             n -= 2;
index 04f3bc2fe3ba2a743bdf7a06560dfdd18d9a4054..33cc3ef04d115052c33fbb007138805a04354971 100644 (file)
@@ -24,7 +24,7 @@ LabelSequence::LabelSequence(const void* buf) {
     // will lead to a crash, so disabling this check is not
     // unsafe. Except for a programming mistake, this case should not
     // happen.
-    if (buf == NULL) {
+    if (!buf) {
         isc_throw(BadValue,
                   "Null pointer passed to LabelSequence constructor");
     }
index d157aa0d1022c4b672bbd1b459581be40bbb07c1..2b521e3ab1c05cf713f39f67cc2150070b1bb825 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
-
+#include <exceptions/isc_assert.h>
 #include <dns/master_lexer.h>
 #include <dns/master_lexer_inputsource.h>
 #include <dns/master_lexer_state.h>
@@ -15,7 +15,6 @@
 #include <boost/lexical_cast.hpp>
 
 #include <bitset>
-#include <cassert>
 #include <limits>
 #include <string>
 #include <vector>
@@ -84,7 +83,7 @@ struct MasterLexer::MasterLexerImpl {
     }
 
     void setTotalSize() {
-        assert(source_ != NULL);
+        isc_throw_assert(source_);
         if (total_size_ != SOURCE_SIZE_UNKNOWN) {
             const size_t current_size = source_->getSize();
             if (current_size != SOURCE_SIZE_UNKNOWN) {
@@ -236,8 +235,8 @@ MasterLexer::getNextToken(Options options) {
     }
     // Make sure a token was produced. Since this Can Not Happen, we assert
     // here instead of throwing.
-    assert(impl_->token_.getType() != MasterToken::ERROR ||
-           impl_->token_.getErrorCode() != MasterToken::NO_TOKEN_PRODUCED);
+    isc_throw_assert(impl_->token_.getType() != MasterToken::ERROR ||
+                     impl_->token_.getErrorCode() != MasterToken::NO_TOKEN_PRODUCED);
     return (impl_->token_);
 }
 
@@ -287,7 +286,7 @@ MasterLexer::getNextToken(MasterToken::Type expect, bool eol_ok) {
             throw LexerError(__FILE__, __LINE__,
                              MasterToken(MasterToken::UNEXPECTED_END));
         }
-        assert(expect == MasterToken::NUMBER);
+        isc_throw_assert(expect == MasterToken::NUMBER);
         throw LexerError(__FILE__, __LINE__,
                          MasterToken(MasterToken::BAD_NUMBER));
     }
@@ -329,7 +328,7 @@ MasterToken::getErrorText() const {
     }
 
     // The class integrity ensures the following:
-    assert(val_.error_code_ < error_text_max_count);
+    isc_throw_assert(val_.error_code_ < error_text_max_count);
     return (error_text[val_.error_code_]);
 }
 
@@ -426,7 +425,7 @@ State::getInstance(ID state_id) {
     // This is a bug of the caller, and this method is only expected to be
     // used by tests, so we just forcefully make it fail by asserting the
     // condition.
-    assert(false);
+    isc_throw_assert(false);
     return (STRING_STATE); // a dummy return, to silence some compilers.
 }
 
@@ -540,7 +539,7 @@ QString::handle(MasterLexer& lexer) const {
         } else if (c == '"') {
             if (escaped) {
                 // found escaped '"'. overwrite the preceding backslash.
-                assert(!data.empty());
+                isc_throw_assert(!data.empty());
                 escaped = false;
                 data.back() = '"';
             } else {
index 0965aa1c1f13e8f13439ec07b747c195bff698da..ddd2da50cc8dc3acf84009516ddef9ecab59f6a3 100644 (file)
@@ -384,7 +384,7 @@ public:
     /// case of failure.
     ///
     /// \return true if pushing the file succeeds; false otherwise.
-    bool pushSource(const char* filename, std::string* error = NULL);
+    bool pushSource(const char* filename, std::string* error = 0);
 
     /// \brief Make the given stream the current input source of MasterLexer.
     ///
index 1a1058fdfeb7bc73a87332e0b47f3a18d68e193e..ef8b078ef6836ca23f4776f3d4a36ae558b8ea72 100644 (file)
@@ -6,12 +6,12 @@
 
 #include <config.h>
 
+#include <exceptions/isc_assert.h>
 #include <dns/master_lexer_inputsource.h>
 #include <dns/master_lexer.h>
 
 #include <istream>
 #include <iostream>
-#include <cassert>
 #include <cerrno>
 #include <cstring>
 
@@ -72,7 +72,7 @@ getStreamSize(std::istream& is) {
         isc_throw(InputSource::OpenError,
                   "failed to seek beginning of input source");
     }
-    assert(len >= 0 || ret == MasterLexer::SOURCE_SIZE_UNKNOWN);
+    isc_throw_assert(len >= 0 || ret == MasterLexer::SOURCE_SIZE_UNKNOWN);
     return (ret);
 }
 
@@ -186,7 +186,7 @@ InputSource::ungetChar() {
 
 void
 InputSource::ungetAll() {
-    assert(total_pos_ >= buffer_pos_);
+    isc_throw_assert(total_pos_ >= buffer_pos_);
     total_pos_ -= buffer_pos_;
     buffer_pos_ = 0;
     line_ = saved_line_;
index 1c48388a6eef83c6f29987f0cf593f3a6af10b22..3c756e9afbf85626c3bcce7dae7aac85c7de0e1f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <exceptions/isc_assert.h>
 #include <dns/master_loader.h>
 #include <dns/master_lexer.h>
 #include <dns/name.h>
@@ -190,7 +191,7 @@ private:
 
         // We move in tandem, there's an extra item included during the
         // initialization, so we can never run out of them
-        assert(!include_info_.empty());
+        isc_throw_assert(!include_info_.empty());
         const IncludeInfo& info(include_info_.back());
         active_origin_ = info.first;
         last_name_ = info.second;
@@ -259,7 +260,7 @@ private:
         } else {
             // If it is not optional, we must not get anything but
             // a string token.
-            assert(is_optional);
+            isc_throw_assert(is_optional);
 
             // We return the newline there. This is because we want to
             // behave the same if there is or isn't the name, leaving the
@@ -443,7 +444,7 @@ private:
                                "last explicitly stated TTL");
             warn_rfc1035_ttl_ = false; // we only warn about this once
         }
-        assert(current_ttl_);
+        isc_throw_assert(current_ttl_);
         return (*current_ttl_);
     }
 
@@ -961,7 +962,7 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
             }
             // We are going to parse an RR, have known the owner name,
             // and are now seeing the next string token in the rest of the RR.
-            assert(next_token.getType() == MasterToken::STRING);
+            isc_throw_assert(next_token.getType() == MasterToken::STRING);
 
             bool explicit_ttl = false;
             const RRType rrtype = parseRRParams(explicit_ttl, next_token);
index 2a4ecf579aad6fa2485770a2e87588309716cb37..5bd9e00ebe95a0cad825a1ed8e27e1032e870070 100644 (file)
@@ -583,7 +583,7 @@ public:
     /// \param tsig_ctx A TSIG context that is to be used for signing the
     /// message
     void toWire(AbstractMessageRenderer& renderer,
-                TSIGContext* tsig_ctx = NULL);
+                TSIGContext* tsig_ctx = 0);
 
     /// Parse options.
     ///
index bc59e16d6387eec91f656c61c47a5b0c8e7c6c77..684c44684928d7bc6c4955a38da4f550604111ae 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
 #include <dns/name.h>
 #include <dns/name_internal.h>
 #include <dns/labelsequence.h>
@@ -126,7 +127,7 @@ private:
                 // on a valid name, which is an assumption for this class.
                 // But we'll abort if a bug could cause an infinite loop.
                 i += 2;
-                assert(i < Name::MAX_WIRE);
+                isc_throw_assert(i < Name::MAX_WIRE);
             }
             llen = buffer[pos];
         } else {
index df48785364938316f9687c348346c7e1b19bdab6..6546c5d754c8cecb7ea79e638d4e6548b154234b 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/master_lexer.h>
@@ -165,7 +166,7 @@ createRdata(const RRType& rrtype, const RRClass& rrclass,
     } while (true);
 
     // We shouldn't reach here
-    assert(false);
+    isc_throw_assert(false);
     return (RdataPtr()); // add explicit return to silence some compilers
 }
 
index adc4e98881e95266ba8d6b9e5bc3e9db8ac8fdfe..39df1bcc1f36ccf207480498879a676438f3adee 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
 #include <dns/exceptions.h>
 #include <dns/master_lexer.h>
 #include <dns/master_loader.h>
@@ -1318,7 +1319,7 @@ SOA::SOA(const Name& mname, const Name& rname, uint32_t serial,
     b.writeUint32(retry);
     b.writeUint32(expire);
     b.writeUint32(minimum);
-    assert(b.getLength() == sizeof(numdata_));
+    isc_throw_assert(b.getLength() == sizeof(numdata_));
     memcpy(numdata_, b.getData(), sizeof(numdata_));
 }
 
index 12d94f2ef316142f4d24545735b40a0711fa6d41..7ac7f3491a2a6c85c0f82b550aa691c8dd196e2d 100644 (file)
@@ -97,7 +97,8 @@ public:
     /// This constructor never throws an exception.
     ///
     /// \param classcode An 16-bit integer code corresponding to the RRClass.
-    explicit RRClass(uint16_t classcode) : classcode_(classcode) {}
+    explicit RRClass(uint16_t classcode) : classcode_(classcode) {
+    }
     ///
     /// A valid string is one of "well-known" textual class representations
     /// such as "IN" or "CH", or in the standard format for "unknown"
@@ -285,18 +286,15 @@ public:
         return (classcode_ < other.classcode_);
     }
 
-    // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS
     static const RRClass& ANY();
     static const RRClass& IN();
     static const RRClass& CH();
     static const RRClass& NONE();
-    // END_WELL_KNOWN_CLASS_DECLARATIONS
 
 private:
     uint16_t classcode_;
 };
 
-// BEGIN_WELL_KNOWN_CLASS_DEFINITIONS
 inline const RRClass&
 RRClass::ANY() {
     static RRClass rrclass(255);
@@ -321,8 +319,6 @@ RRClass::NONE() {
     return (rrclass);
 }
 
-// END_WELL_KNOWN_CLASS_DEFINITIONS
-
 ///
 /// \brief Insert the \c RRClass as a string into stream.
 ///
index f047188e9f0f7e93311b6096880e4c60f72c167c..2a485306a877b18798bc52e2ce23580bc05d318e 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
 #include <dns/rrparamregistry.h>
 #include <dns/rrclass.h>
 #include <dns/rrtype.h>
@@ -194,7 +195,6 @@ RRParamRegistry::RRParamRegistry() : impl_(new RRParamRegistryImpl()) {
 
     // set up parameters for well-known RRs
     try {
-        // BEGIN_WELL_KNOWN_PARAMS
         add("A", 1, "IN", 1, RdataFactoryPtr(new RdataFactory<in::A>()));
         add("NS", 2, "IN", 1, RdataFactoryPtr(new RdataFactory<generic::NS>()));
         add("SOA", 6, "IN", 1, RdataFactoryPtr(new RdataFactory<generic::SOA>()));
@@ -300,7 +300,6 @@ RRParamRegistry::RRParamRegistry() : impl_(new RRParamRegistryImpl()) {
         // Meta classes
         addClass("CH", 3);
         addClass("NONE", 254);
-        // END_WELL_KNOWN_PARAMS
     } catch (...) {
         throw;
     }
@@ -403,7 +402,7 @@ bool CICharEqual(char c1, char c2) {
 
 bool
 caseStringEqual(const string& s1, const string& s2, size_t n) {
-    assert(s1.size() >= n && s2.size() >= n);
+    isc_throw_assert(s1.size() >= n && s2.size() >= n);
 
     return (mismatch(s1.begin(), s1.begin() + n, s2.begin(), CICharEqual).first
             == s1.begin() + n);
@@ -457,7 +456,7 @@ removeParam(uint16_t code, MC& codemap, MS& stringmap) {
     if (found != codemap.end()) {
         size_t erased = stringmap.erase(found->second->code_string_);
         // We must have a corresponding entry of the str2 map exists
-        assert(erased == 1);
+        isc_throw_assert(erased == 1);
 
         codemap.erase(found);
 
index 1ab3bde03125279e7db2342556078ef1b786ccf1..1360c1255dda541cf452b611cc244b396df47ba8 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <exceptions/isc_assert.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rrclass.h>
@@ -97,7 +98,7 @@ rrsetToWire(const AbstractRRset& rrset, T& output, const size_t limit) {
     // other options.  Details to be considered.
     do {
         const size_t pos0 = output.getLength();
-        assert(pos0 < 65536);
+        isc_throw_assert(pos0 < 65536);
 
         rrset.getName().toWire(output);
         rrset.getType().toWire(output);
@@ -203,7 +204,7 @@ BasicRRsetImpl::toWire(AbstractMessageRenderer& renderer, size_t limit) const {
     // other options.  Details to be considered.
     for (auto const& rdata : rdatalist_) {
         const size_t pos0 = renderer.getLength();
-        assert(pos0 < 65536);
+        isc_throw_assert(pos0 < 65536);
 
         name_.toWire(renderer);
         rrtype_.toWire(renderer);
@@ -320,7 +321,7 @@ BasicRRset::getLength() const {
         rrlen += 2; // RDLENGTH field
         rrlen += it->getCurrent().getLength();
 
-        assert(length + rrlen < 65536);
+        isc_throw_assert(length + rrlen < 65536);
         length += rrlen;
 
         it->next();
@@ -369,7 +370,7 @@ RRset::getLength() const {
         const uint16_t rrsigs_length = rrsig_->getLength();
         // the uint16_ts are promoted to ints during addition below, so
         // it won't overflow a 16-bit register.
-        assert(length + rrsigs_length < 65536);
+        isc_throw_assert(length + rrsigs_length < 65536);
         length += rrsigs_length;
     }
 
index 8d9a7112d064934f395e558e648dd80ad1debabe..3b543293dd002f43f11ea6d05884c5c3482db4b9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <exceptions/isc_assert.h>
 #include <dns/messagerenderer.h>
 #include <dns/rrttl.h>
 #include <util/buffer.h>
@@ -127,7 +128,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) {
 
             // seconds cannot be out of range at this point.
             const uint64_t seconds = value * multiply;
-            assert(seconds <= 0xffffffff);
+            isc_throw_assert(seconds <= 0xffffffff);
 
             // Add what we found
             val += seconds;
index 63d8e5282ed0b757a3d7f8b0c7742e3ba0bc3248..ae575d06149b4fd76392cc9114e6d5adb2b7ecab 100644 (file)
@@ -104,7 +104,8 @@ public:
     /// This constructor never throws an exception.
     ///
     /// \param typecode An 16-bit integer code corresponding to the RRType.
-    explicit RRType(uint16_t typecode) : typecode_(typecode) {}
+    explicit RRType(uint16_t typecode) : typecode_(typecode) {
+    }
     /// Constructor from a string.
     ///
     /// A valid string is one of "well-known" textual type representations
@@ -257,7 +258,6 @@ public:
     }
     //@}
 
-    // BEGIN_WELL_KNOWN_TYPE_DECLARATIONS
     static const RRType& A();
     static const RRType& NS();
     static const RRType& SOA();
@@ -270,14 +270,11 @@ public:
     static const RRType& TKEY();
     static const RRType& TSIG();
     static const RRType& ANY();
-    // END_WELL_KNOWN_TYPE_DECLARATIONS
 
 private:
     uint16_t typecode_;
 };
 
-// BEGIN_WELL_KNOWN_TYPE_DEFINITIONS
-
 inline const RRType&
 RRType::A() {
     static RRType rrtype(1);
@@ -350,8 +347,6 @@ RRType::ANY() {
     return (rrtype);
 }
 
-// END_WELL_KNOWN_TYPE_DEFINITIONS
-
 ///
 /// \brief Insert the \c RRType as a string into stream.
 ///
index 850d018158399cd355118c93ce6b08b376766bac..db5fcd6dec632f0fb943401334d5fe06034185c7 100644 (file)
@@ -859,7 +859,7 @@ commonTSIGToWireCheck(Message& message, MessageRenderer& renderer,
                       TSIGContext& tsig_ctx, const char* const expected_file,
                       unsigned int message_flags = RD_FLAG,
                       RRType qtype = RRType::A(),
-                      const vector<const char*>* answer_data = NULL) {
+                      const vector<const char*>* answer_data = 0) {
     message.setOpcode(Opcode::QUERY());
     message.setRcode(Rcode::NOERROR());
     if ((message_flags & QR_FLAG) != 0) {
@@ -874,7 +874,7 @@ commonTSIGToWireCheck(Message& message, MessageRenderer& renderer,
     message.addQuestion(Question(Name("www.example.com"), RRClass::IN(),
                                  qtype));
 
-    if (answer_data != NULL) {
+    if (answer_data) {
         RRsetPtr ans_rrset(new RRset(Name("www.example.com"), RRClass::IN(),
                                      qtype, RRTTL(86400)));
         for (auto const& it : *answer_data) {
@@ -1026,7 +1026,7 @@ TEST_F(MessageTest, toWireTSIGTruncation3) {
     EXPECT_TRUE(message_parse.getHeaderFlag(Message::HEADERFLAG_TC));
     // Note that the number of questions are 66, not 67 as we tried to add.
     EXPECT_EQ(66, message_parse.getRRCount(Message::SECTION_QUESTION));
-    EXPECT_TRUE(message_parse.getTSIGRecord() != NULL);
+    EXPECT_TRUE(message_parse.getTSIGRecord());
 }
 
 TEST_F(MessageTest, toWireTSIGNoTruncation) {
index 607e6afe6b9e343943ac1cda6de7029e56d3aa5c..fb6de53d42a275b5208ab2c86ca3dde3bb4d13cb 100644 (file)
@@ -161,7 +161,7 @@ TEST_F(CharStringTest, charStringToString) {
         uint8_t idata[32];
         size_t length = std::strlen(cur->data);
         // length (1 byte) + string (length bytes)
-        assert(sizeof(idata) > length);
+        ASSERT_TRUE(sizeof(idata) > length);
         idata[0] = static_cast<uint8_t>(length);
         std::memcpy(idata + 1, cur->data, length);
         const CharString test_data(idata, idata + length + 1);
index 6be2d08a397a7b76f66c8aed284b94f0bc000fdd..a235183529b2be2f43cecbe4296d71285be5d44c 100644 (file)
@@ -50,7 +50,7 @@ TEST_F(Rdata_OPT_Test, createFromWire) {
     // we can only check these don't throw.
     EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"),
                                          "rdata_opt_fromWire1"));
-    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::ANY(),
+    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
                                          "rdata_opt_fromWire1", 2));
 
     // Short RDLEN. This throws InvalidRdataLength even if subsequent
@@ -119,7 +119,7 @@ TEST_F(Rdata_OPT_Test, compare) {
     const generic::OPT rdata_opt;
 
     EXPECT_THROW(rdata_opt.compare(
-                  *rdataFactoryFromFile(RRType::OPT(), RRClass::ANY(),
+                  *rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
                                         "rdata_opt_fromWire1", 2)),
                  isc::InvalidOperation);
 
index 21f4dc48542b1efcc26c038661f3837749e24806..f0da2436e781d7e5e13df4cfdf3ccaa857e46ac1 100644 (file)
@@ -36,7 +36,7 @@ protected:
     {}
 
     template <typename ExForString, typename ExForLexer>
-    void checkFromTextSOA(const string& soa_txt, const Name* origin = NULL,
+    void checkFromTextSOA(const string& soa_txt, const Name* origin = 0,
                           bool throw_str_version = true,
                           bool throw_lexer_version = true)
     {
index dcb5ac168ba14bc48f810c7e7cc650ee905315f0..35cbf90f21eb71486f89d2cb63e133b58c723522 100644 (file)
@@ -240,7 +240,7 @@ makeLargest(vector<uint8_t>& data) {
     data.push_back(254);
     data.insert(data.end(), 254, ch);
 
-    assert(data.size() == 65535);
+    ASSERT_TRUE(data.size() == 65535);
 }
 
 TYPED_TEST(Rdata_TXT_LIKE_Test, createFromWire) {
index c412bbbc0675d3b92ea55a6ec929e877bbc1391c..74bd5c46529116876aace244913ec868c5cd2699 100644 (file)
@@ -45,7 +45,7 @@ protected:
                        const RdataType& rdata_expected,
                        bool throw_str_version = true,
                        bool throw_lexer_version = true,
-                       const Name* origin = NULL) {
+                       const Name* origin = 0) {
         SCOPED_TRACE(rdata_txt);
 
         if (throw_str_version) {
index 54e616cd77d26a77b641e6df4630a014c1861226..c5fb01eab0d9bec0ae51250042ec0e2b315538e4 100644 (file)
@@ -153,8 +153,8 @@ TEST_F(RRClassTest, LeftShiftOperator) {
 // http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
 struct ClassParam {
     const char* const txt;      // "IN", "CH", etc
-    const uint16_t code;        // 1, 3,
-    const RRClass& (*obj)();     // RRClass::IN(), etc
+    const uint16_t code;        // 1, 3, etc
+    const RRClass& (*obj)();    // RRClass::IN(), RRClass::CH(), etc
 } known_classes[] = {
     {"IN", 1, RRClass::IN}, {"CH", 3, RRClass::CH},
     {"NONE", 254, RRClass::NONE}, {"ANY", 255, RRClass::ANY},
index 97975409b81da2c8e1d2089e944464de5dbbe0fd..d80e4a3fe2034688630e970349ef5f1550a627d8 100644 (file)
@@ -149,12 +149,101 @@ struct TypeParam {
     const uint16_t code;        // 1, 28, 2, etc
     const RRType& (*obj)();     // RRType::A(), etc
 } known_types[] = {
-    {"A", 1, RRType::A}, {"NS", 2, RRType::NS},
-    {"SOA", 6, RRType::SOA}, {"PTR", 12, RRType::PTR},
-    {"TXT", 16, RRType::TXT}, {"AAAA", 28, RRType::AAAA},
-    {"OPT", 41, RRType::OPT}, {"RRSIG", 46, RRType::RRSIG},
-    {"DHCID", 49, RRType::DHCID}, {"TKEY", 249, RRType::TKEY},
-    {"TSIG", 250, RRType::TSIG}, {"ANY", 255, RRType::ANY},
+    {"A", 1, RRType::A},
+    {"NS", 2, RRType::NS},
+    {"SOA", 6, RRType::SOA},
+    {"PTR", 12, RRType::PTR},
+    {"TXT", 16, RRType::TXT},
+    {"AAAA", 28, RRType::AAAA},
+    {"OPT", 41, RRType::OPT},
+    {"RRSIG", 46, RRType::RRSIG},
+    {"DHCID", 49, RRType::DHCID},
+    {"TKEY", 249, RRType::TKEY},
+    {"TSIG", 250, RRType::TSIG},
+    {"ANY", 255, RRType::ANY},
+    {"MD", 3, []() -> const RRType& {static const RRType r("MD"); return (r);}},
+    {"MF", 4, []() -> const RRType& {static const RRType r("MF"); return (r);}},
+    {"CNAME", 5, []() -> const RRType& {static const RRType r("CNAME"); return (r);}},
+    {"MB", 7, []() -> const RRType& {static const RRType r("MB"); return (r);}},
+    {"MG", 8, []() -> const RRType& {static const RRType r("MG"); return (r);}},
+    {"MR", 9, []() -> const RRType& {static const RRType r("MR"); return (r);}},
+    {"NULL", 10, []() -> const RRType& {static const RRType r("NULL"); return (r);}},
+    {"WKS", 11, []() -> const RRType& {static const RRType r("WKS"); return (r);}},
+    {"HINFO", 13, []() -> const RRType& {static const RRType r("HINFO"); return (r);}},
+    {"MINFO", 14, []() -> const RRType& {static const RRType r("MINFO"); return (r);}},
+    {"MX", 15, []() -> const RRType& {static const RRType r("MX"); return (r);}},
+    {"RP", 17, []() -> const RRType& {static const RRType r("RP"); return (r);}},
+    {"AFSDB", 18, []() -> const RRType& {static const RRType r("AFSDB"); return (r);}},
+    {"X25", 19, []() -> const RRType& {static const RRType r("X25"); return (r);}},
+    {"ISDN", 20, []() -> const RRType& {static const RRType r("ISDN"); return (r);}},
+    {"RT", 21, []() -> const RRType& {static const RRType r("RT"); return (r);}},
+    {"NSAP", 22, []() -> const RRType& {static const RRType r("NSAP"); return (r);}},
+    {"NSAP-PTR", 23, []() -> const RRType& {static const RRType r("NSAP-PTR"); return (r);}},
+    {"SIG", 24, []() -> const RRType& {static const RRType r("SIG"); return (r);}},
+    {"KEY", 25, []() -> const RRType& {static const RRType r("KEY"); return (r);}},
+    {"PX", 26, []() -> const RRType& {static const RRType r("PX"); return (r);}},
+    {"GPOS", 27, []() -> const RRType& {static const RRType r("GPOS"); return (r);}},
+    {"LOC", 29, []() -> const RRType& {static const RRType r("LOC"); return (r);}},
+    {"NXT", 30, []() -> const RRType& {static const RRType r("NXT"); return (r);}},
+    {"EID", 31, []() -> const RRType& {static const RRType r("EID"); return (r);}},
+    {"NIMLOC", 32, []() -> const RRType& {static const RRType r("NIMLOC"); return (r);}},
+    {"SRV", 33, []() -> const RRType& {static const RRType r("SRV"); return (r);}},
+    {"ATMA", 34, []() -> const RRType& {static const RRType r("ATMA"); return (r);}},
+    {"NAPTR", 35, []() -> const RRType& {static const RRType r("NAPTR"); return (r);}},
+    {"KX", 36, []() -> const RRType& {static const RRType r("KX"); return (r);}},
+    {"CERT", 37, []() -> const RRType& {static const RRType r("CERT"); return (r);}},
+    {"A6", 38, []() -> const RRType& {static const RRType r("A6"); return (r);}},
+    {"DNAME", 39, []() -> const RRType& {static const RRType r("DNAME"); return (r);}},
+    {"SINK", 40, []() -> const RRType& {static const RRType r("SINK"); return (r);}},
+    {"APL", 42, []() -> const RRType& {static const RRType r("APL"); return (r);}},
+    {"DS", 43, []() -> const RRType& {static const RRType r("DS"); return (r);}},
+    {"SSHFP", 44, []() -> const RRType& {static const RRType r("SSHFP"); return (r);}},
+    {"IPSECKEY", 45, []() -> const RRType& {static const RRType r("IPSECKEY"); return (r);}},
+    {"NSEC", 47, []() -> const RRType& {static const RRType r("NSEC"); return (r);}},
+    {"DNSKEY", 48, []() -> const RRType& {static const RRType r("DNSKEY"); return (r);}},
+    {"NSEC3", 50, []() -> const RRType& {static const RRType r("NSEC3"); return (r);}},
+    {"NSEC3PARAM", 51, []() -> const RRType& {static const RRType r("NSEC3PARAM"); return (r);}},
+    {"TLSA", 52, []() -> const RRType& {static const RRType r("TLSA"); return (r);}},
+    {"SMIMEA", 53, []() -> const RRType& {static const RRType r("SMIMEA"); return (r);}},
+    // Unassigned  54
+    {"HIP", 55, []() -> const RRType& {static const RRType r("HIP"); return (r);}},
+    {"NINFO", 56, []() -> const RRType& {static const RRType r("NINFO"); return (r);}},
+    {"RKEY", 57, []() -> const RRType& {static const RRType r("RKEY"); return (r);}},
+    {"TALINK", 58, []() -> const RRType& {static const RRType r("TALINK"); return (r);}},
+    {"CDS", 59, []() -> const RRType& {static const RRType r("CDS"); return (r);}},
+    {"CDNSKEY", 60, []() -> const RRType& {static const RRType r("CDNSKEY"); return (r);}},
+    {"OPENPGPKEY", 61, []() -> const RRType& {static const RRType r("OPENPGPKEY"); return (r);}},
+    {"CSYNC", 62 , []() -> const RRType& {static const RRType r("CSYNC"); return (r);}},
+    {"ZONEMD", 63, []() -> const RRType& {static const RRType r("ZONEMD"); return (r);}},
+    {"SVCB", 64, []() -> const RRType& {static const RRType r("SVCB"); return (r);}},
+    {"HTTPS", 65, []() -> const RRType& {static const RRType r("HTTPS"); return (r);}},
+    // Unassigned  66-98
+    {"SPF", 99, []() -> const RRType& {static const RRType r("SPF"); return (r);}},
+    {"UINFO", 100, []() -> const RRType& {static const RRType r("UINFO"); return (r);}},
+    {"UID", 101, []() -> const RRType& {static const RRType r("UID"); return (r);}},
+    {"GID", 102, []() -> const RRType& {static const RRType r("GID"); return (r);}},
+    {"UNSPEC", 103, []() -> const RRType& {static const RRType r("UNSPEC"); return (r);}},
+    {"NID", 104, []() -> const RRType& {static const RRType r("NID"); return (r);}},
+    {"L32", 105, []() -> const RRType& {static const RRType r("L32"); return (r);}},
+    {"L64", 106, []() -> const RRType& {static const RRType r("L64"); return (r);}},
+    {"LP", 107, []() -> const RRType& {static const RRType r("LP"); return (r);}},
+    {"EUI48", 108, []() -> const RRType& {static const RRType r("EUI48"); return (r);}},
+    {"EUI64", 109, []() -> const RRType& {static const RRType r("EUI64"); return (r);}},
+    // Unassigned  110-248
+    {"IXFR", 251, []() -> const RRType& {static const RRType r("IXFR"); return (r);}},
+    {"AXFR",  252, []() -> const RRType& {static const RRType r("AXFR"); return (r);}},
+    {"MAILB", 253, []() -> const RRType& {static const RRType r("MAILB"); return (r);}},
+    {"MAILA", 254, []() -> const RRType& {static const RRType r("MAILA"); return (r);}},
+    {"ANY", 255, []() -> const RRType& {static const RRType r("ANY"); return (r);}}, // also known as "*"
+    {"URI", 256, []() -> const RRType& {static const RRType r("URI"); return (r);}},
+    {"CAA", 257, []() -> const RRType& {static const RRType r("CAA"); return (r);}},
+    {"AVC", 258, []() -> const RRType& {static const RRType r("AVC"); return (r);}},
+    {"DOA", 259, []() -> const RRType& {static const RRType r("DOA"); return (r);}},
+    {"AMTRELAY", 260, []() -> const RRType& {static const RRType r("AMTRELAY"); return (r);}},
+    {"RESINFO", 261, []() -> const RRType& {static const RRType r("RESINFO"); return (r);}},
+    // Unassigned  262-32767
+    {"TA", 32768, []() -> const RRType& {static const RRType r("TA"); return (r);}},
+    {"DLV", 32769, []() -> const RRType& {static const RRType r("DLV"); return (r);}},
     {NULL, 0, NULL}
 };
 
index ca2a28c68e253b2b1b9256b4903e911a46f1a62d..7f6fa02bc83a79f6c24bdbcd4197cede22b11afc 100644 (file)
@@ -210,9 +210,9 @@ commonSignChecks(ConstTSIGRecordPtr tsig, uint16_t expected_qid,
                  const uint8_t* expected_mac, size_t expected_maclen,
                  uint16_t expected_error = 0,
                  uint16_t expected_otherlen = 0,
-                 const uint8_t* expected_otherdata = NULL,
+                 const uint8_t* expected_otherdata = 0,
                  const Name& expected_algorithm = TSIGKey::HMACMD5_NAME()) {
-    ASSERT_TRUE(tsig != NULL);
+    ASSERT_TRUE(tsig);
     const TSIG& tsig_rdata = tsig->getRdata();
 
     EXPECT_EQ(expected_algorithm, tsig_rdata.getAlgorithm());
@@ -567,7 +567,7 @@ TEST_F(TSIGTest, signContinuation) {
     // Create and sign the AXFR request
     ConstTSIGRecordPtr tsig = createMessageAndSign(axfr_qid, zone_name,
                                                    tsig_ctx.get(), 0,
-                                                   RRType(252));
+                                                   RRType("AXFR"));
     // Then verify it (the wire format test data should contain the same
     // message data, and verification should succeed).
     received_data.clear();
@@ -581,7 +581,7 @@ TEST_F(TSIGTest, signContinuation) {
 
     // Create and sign the first response message
     tsig = createMessageAndSign(axfr_qid, zone_name, tsig_verify_ctx.get(),
-                                AA_FLAG|QR_FLAG, RRType(252),
+                                AA_FLAG|QR_FLAG, RRType("AXFR"),
                                 "ns.example.com. root.example.com. "
                                 "2011041503 7200 3600 2592000 1200",
                                 &RRType::SOA());
@@ -603,7 +603,7 @@ TEST_F(TSIGTest, signContinuation) {
     {
         SCOPED_TRACE("Sign test for continued response in TCP stream");
         tsig = createMessageAndSign(axfr_qid, zone_name, tsig_verify_ctx.get(),
-                                    AA_FLAG|QR_FLAG, RRType(252),
+                                    AA_FLAG|QR_FLAG, RRType("AXFR"),
                                     "ns.example.com.", &RRType::NS(), false);
         commonSignChecks(tsig, axfr_qid, 0x4da8e951, expected_mac,
                          sizeof(expected_mac));
index 7281d9ab04851b30491d1b596e47730aa7cf9920..e85d636670fff66f056e4bbe207e16a6fdbf2928 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_hmac.h>
 #include <dns/rdataclass.h>
@@ -164,7 +165,7 @@ void
 TSIGContext::TSIGContextImpl::digestPreviousMAC(HMACPtr hmac) {
     // We should have ensured the digest size fits 16 bits within this class
     // implementation.
-    assert(previous_digest_.size() <= 0xffff);
+    isc_throw_assert(previous_digest_.size() <= 0xffff);
 
     if (previous_digest_.empty()) {
         // The previous digest was already used. We're in the middle of
@@ -400,7 +401,7 @@ TSIGContext::sign(const uint16_t qid, const void* const data,
 
     // Get the final digest, update internal state, then finish.
     vector<uint8_t> digest = hmac->sign(impl_->digest_len_);
-    assert(digest.size() <= 0xffff); // cryptolink API should have ensured it.
+    isc_throw_assert(digest.size() <= 0xffff); // cryptolink API should have ensured it.
     ConstTSIGRecordPtr tsig(new TSIGRecord(
                                 impl_->key_.getKeyName(),
                                 any::TSIG(impl_->key_.getAlgorithmName(),