[svn] commit: r942 - in /branches/each-ds/src/lib/dns/cpp: ./ rdata/generic/ testdata/

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Feb 24 02:05:19 UTC 2010


Author: each
Date: Wed Feb 24 02:05:19 2010
New Revision: 942

Log:
- unit tests for hex encode/decode
- unit tests for new rdata types
- several bugs fixed, including missing buffer constructors for DNSKEY,
  DS and NSEC
- added dnstime.{cc,h} with DNSSECTimeFromText() and DNSSECTimeToText(),
  instead of having those routines live in the RRSIG implementation

Added:
    branches/each-ds/src/lib/dns/cpp/dnstime.cc
    branches/each-ds/src/lib/dns/cpp/dnstime.h
    branches/each-ds/src/lib/dns/cpp/hex_unittest.cc
    branches/each-ds/src/lib/dns/cpp/testdata/rdata_dnskey_fromWire
    branches/each-ds/src/lib/dns/cpp/testdata/rdata_ds_fromWire
    branches/each-ds/src/lib/dns/cpp/testdata/rdata_nsec_fromWire
Modified:
    branches/each-ds/src/lib/dns/cpp/Makefile.am
    branches/each-ds/src/lib/dns/cpp/base64.cc
    branches/each-ds/src/lib/dns/cpp/base64.h
    branches/each-ds/src/lib/dns/cpp/base64_unittest.cc
    branches/each-ds/src/lib/dns/cpp/hex.cc
    branches/each-ds/src/lib/dns/cpp/rdata.cc
    branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.cc
    branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.h
    branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.cc
    branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.h
    branches/each-ds/src/lib/dns/cpp/rdata/generic/nsec_47.cc
    branches/each-ds/src/lib/dns/cpp/rdata/generic/rrsig_46.cc
    branches/each-ds/src/lib/dns/cpp/rdata_unittest.cc

Modified: branches/each-ds/src/lib/dns/cpp/Makefile.am
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/Makefile.am (original)
+++ branches/each-ds/src/lib/dns/cpp/Makefile.am Wed Feb 24 02:05:19 2010
@@ -17,6 +17,7 @@
 libdns_la_SOURCES += question.h question.cc
 libdns_la_SOURCES += message.h message.cc
 libdns_la_SOURCES += base64.h base64.cc
+libdns_la_SOURCES += dnstime.h dnstime.cc
 libdns_la_SOURCES += hex.h hex.cc
 
 rrclass.h: rrclass-placeholder.h
@@ -40,7 +41,7 @@
 run_unittests_SOURCES += rrparamregistry_unittest.cc
 run_unittests_SOURCES += message_unittest.cc
 run_unittests_SOURCES += base64_unittest.cc
-#run_unittests_SOURCES += hex_unittest.cc
+run_unittests_SOURCES += hex_unittest.cc
 run_unittests_SOURCES += run_unittests.cc
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)

Modified: branches/each-ds/src/lib/dns/cpp/base64.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/base64.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/base64.cc Wed Feb 24 02:05:19 2010
@@ -14,6 +14,7 @@
 
 // $Id$
 
+#include <stdint.h>
 #include <cassert>
 #include <iterator>
 #include <string>
@@ -33,13 +34,12 @@
 namespace dns {
 
 namespace {
-const char BINARY_ZERO_CODE = 0;
+const uint8_t BINARY_ZERO_CODE = 0;
 
-typedef
-class BinaryNormalizer : public iterator<input_iterator_tag, char> {
+class BinaryNormalizer : public iterator<input_iterator_tag, uint8_t> {
 public:
-    BinaryNormalizer(const vector<char>::const_iterator& base,
-                     const vector<char>::const_iterator& base_end) :
+    BinaryNormalizer(const vector<uint8_t>::const_iterator& base,
+                     const vector<uint8_t>::const_iterator& base_end) :
         base_(base), base_end_(base_end), in_pad_(false)
     {}
     BinaryNormalizer& operator++()
@@ -52,7 +52,7 @@
         }
         return (*this);
     }
-    const char& operator*() const {
+    const uint8_t& operator*() const {
         if (in_pad_) {
             return (BINARY_ZERO_CODE);
         } else {
@@ -64,8 +64,8 @@
         return (base_ == other.base_);
     }
 private:
-    vector<char>::const_iterator base_;
-    const vector<char>::const_iterator base_end_;
+    vector<uint8_t>::const_iterator base_;
+    const vector<uint8_t>::const_iterator base_end_;
     bool in_pad_;
 };
 
@@ -74,7 +74,7 @@
 } // end of anonymous namespace
 
 string
-encodeBase64(const vector<char>& binary)
+encodeBase64(const vector<uint8_t>& binary)
 {
     // calculate the resulting length.  it's the smallest multiple of 4
     // equal to or larger than 4/3 * original data length.
@@ -138,7 +138,7 @@
 } // end of anonymous namespace
 
 void
-decodeBase64(const string& base64, vector<char>& result)
+decodeBase64(const string& base64, vector<uint8_t>& result)
 {
     // enumerate the number of trailing padding characters (=), ignoring
     // white spaces.  since base64_from_binary doesn't accept padding,
@@ -173,7 +173,7 @@
     // Confirm the original base64 text is the canonical encoding of the
     // data.
     assert(result.size() >= padlen);
-    vector<char>::const_reverse_iterator rit = result.rbegin();
+    vector<uint8_t>::const_reverse_iterator rit = result.rbegin();
     for (int i = 0; i < padlen; ++i, ++rit) {
         if (*rit != 0) {
             dns_throw(BadBase64String, "Non 0 bits included in padding");

Modified: branches/each-ds/src/lib/dns/cpp/base64.h
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/base64.h (original)
+++ branches/each-ds/src/lib/dns/cpp/base64.h Wed Feb 24 02:05:19 2010
@@ -16,6 +16,8 @@
 
 #ifndef __BASE64_H
 #define __BASE64_H 1
+
+#include <stdint.h>
 
 #include <string>
 #include <vector>
@@ -41,8 +43,8 @@
         isc::Exception(file, line, what) {}
 };
 
-std::string encodeBase64(const std::vector<char>& binary);
-void decodeBase64(const std::string& base64, std::vector<char>& result);
+std::string encodeBase64(const std::vector<uint8_t>& binary);
+void decodeBase64(const std::string& base64, std::vector<uint8_t>& result);
 }
 }
 

Modified: branches/each-ds/src/lib/dns/cpp/base64_unittest.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/base64_unittest.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/base64_unittest.cc Wed Feb 24 02:05:19 2010
@@ -43,11 +43,11 @@
         test_sequence.push_back(StringPair("foobar", "Zm9vYmFy"));
     }
     vector<StringPair> test_sequence;
-    vector<char> decoded_data;
+    vector<uint8_t> decoded_data;
 };
 
 void
-decodeCheck(const string& input_string, vector<char>& output,
+decodeCheck(const string& input_string, vector<uint8_t>& output,
             const string& expected)
 {
     decodeBase64(input_string, output);

Modified: branches/each-ds/src/lib/dns/cpp/hex.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/hex.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/hex.cc Wed Feb 24 02:05:19 2010
@@ -16,6 +16,7 @@
 
 #include <cassert>
 #include <iterator>
+#include <iomanip>
 #include <iostream>
 #include <sstream>
 #include <string>
@@ -39,9 +40,9 @@
 std::string
 encodeHex(const std::vector<uint8_t>& binary)
 {
-    // calculate the resulting length.  it should be half the
+    // calculate the resulting length.  it should be twice the
     // original data length
-    size_t len = (binary.size() / 2);
+    size_t len = (binary.size() * 2);
     std::ostringstream hex;
 
     BOOST_FOREACH(uint8_t octet, binary) {
@@ -55,11 +56,24 @@
 decodeHex(const std::string& hex, std::vector<uint8_t>& result)
 {
     result.clear();
-    for(size_t i = 0; i < hex.size() / 2; ++i) {
-        std::istringstream iss(hex.substr(i * 2, 2));
-        uint8_t n;
-        iss >> std::hex >> n;
+    std::istringstream iss(hex);
+    char c1, c2;
+    uint8_t n;
+
+    iss.width(1);
+    if ((hex.size() % 2) == 1) {
+        iss >> c2;
+        n = strchr(hexdigits, c2) - hexdigits;
         result.push_back(n);
+    }
+    while (!iss.eof()) {
+        iss >> c1 >> c2;;
+        n = (strchr(hexdigits, c1) - hexdigits) << 4;
+        n |= (strchr(hexdigits, c2) - hexdigits);
+
+        if (!iss.bad() && !iss.fail()) {
+            result.push_back(n);
+        }
     }
 }
 

Modified: branches/each-ds/src/lib/dns/cpp/rdata.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata.cc Wed Feb 24 02:05:19 2010
@@ -16,6 +16,7 @@
 
 #include <cctype>
 #include <string>
+#include <iostream>
 
 #include <stdint.h>
 #include <string.h>

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.cc Wed Feb 24 02:05:19 2010
@@ -26,6 +26,7 @@
 #include "rdata.h"
 #include "rdataclass.h"
 #include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
 
 #include <stdio.h>
 #include <time.h>
@@ -38,7 +39,7 @@
 struct DNSKEYImpl {
     // straightforward representation of DNSKEY RDATA fields
     DNSKEYImpl(uint16_t flags, uint8_t protocol, uint8_t algorithm,
-               const vector<char>& keydata) :
+               const vector<uint8_t>& keydata) :
         flags_(flags), protocol_(protocol), algorithm_(algorithm),
         keydata_(keydata)
     {}
@@ -46,7 +47,7 @@
     uint16_t flags_;
     uint8_t protocol_;
     uint8_t algorithm_;
-    const vector<char> keydata_;
+    const vector<uint8_t> keydata_;
 };
 
 DNSKEY::DNSKEY(const string& dnskey_str) :
@@ -70,7 +71,7 @@
         dns_throw(InvalidRdataText, "DNSKEY algorithm out of range");
     }
 
-    vector<char> keydata;
+    vector<uint8_t> keydata;
     decodeBase64(keydatabuf.str(), keydata);
 
     impl_ = new DNSKEYImpl(flags, protocol, algorithm, keydata);
@@ -78,6 +79,17 @@
 
 DNSKEY::DNSKEY(InputBuffer& buffer, size_t rdata_len)
 {
+    uint16_t flags = buffer.readUint16();
+    uint16_t protocol = buffer.readUint8();
+    uint16_t algorithm = buffer.readUint8();
+    vector<uint8_t> keydata;
+
+    rdata_len -= 4;
+    for (int i = 0; i < rdata_len; i++) {
+        keydata.push_back(buffer.readUint8());
+    }
+
+    impl_ = new DNSKEYImpl(flags, protocol, algorithm, keydata);
 }
 
 DNSKEY::DNSKEY(const DNSKEY& source) :
@@ -157,5 +169,41 @@
     }
 }
 
+const uint16_t
+DNSKEY::getID() const
+{
+    if (impl_->algorithm_ == 1) {
+        int len = impl_->keydata_.size();
+        return ((impl_->keydata_[len - 3] << 8) + impl_->keydata_[len - 2]);
+    }
+
+    uint32_t ac = impl_->flags_;
+    ac += (impl_->protocol_ << 8);
+    ac += impl_->algorithm_;
+    
+    int i;
+    size_t size = impl_->keydata_.size();
+    for (i = 0; i < size; i += 2) {
+        ac += (impl_->keydata_[i] << 8) + impl_->keydata_[i + 1];
+    }
+    if (i > size) {
+        ac += (impl_->keydata_[size] << 8);
+    }
+    
+    ac += (ac >> 16) & 0xffff;
+    ac &= 0xffff;
+    return (ac);
+}
+
+const uint16_t
+DNSKEY::getFlags() const {
+    return (impl_->flags_);
+}
+
+const uint8_t
+DNSKEY::getAlg() const {
+    return (impl_->algorithm_);
+}
+
 // END_RDATA_NAMESPACE
 // END_ISC_NAMESPACE

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.h
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.h (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/dnskey_48.h Wed Feb 24 02:05:19 2010
@@ -40,6 +40,14 @@
     // END_COMMON_MEMBERS
     DNSKEY& operator=(const DNSKEY& source);
     ~DNSKEY();
+
+    ///
+    /// Specialized methods
+    ///
+    const uint16_t getID() const;
+    const uint16_t getFlags() const;
+    const uint8_t getAlg() const;
+
 private:
     DNSKEYImpl* impl_;
 };

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.cc Wed Feb 24 02:05:19 2010
@@ -78,6 +78,17 @@
 
 DS::DS(InputBuffer& buffer, size_t rdata_len)
 {
+    uint16_t keyid = buffer.readUint16();
+    uint16_t algorithm = buffer.readUint8();
+    uint16_t digest_type = buffer.readUint8();
+    vector<uint8_t> digest;
+
+    rdata_len -= 4;
+    for (int i = 0; i < rdata_len; i++) {
+        digest.push_back(buffer.readUint8());
+    }
+
+    impl_ = new DSImpl(keyid, algorithm, digest_type, digest);
 }
 
 DS::DS(const DS& source) :
@@ -157,5 +168,10 @@
     }
 }
 
+const uint16_t
+DS::getID() const {
+    return impl_->keyid_;
+}
+
 // END_RDATA_NAMESPACE
 // END_ISC_NAMESPACE

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.h
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.h (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/ds_43.h Wed Feb 24 02:05:19 2010
@@ -40,6 +40,11 @@
     // END_COMMON_MEMBERS
     DS& operator=(const DS& source);
     ~DS();
+
+    ///
+    /// Specialized methods
+    ///
+    const uint16_t getID() const;
 private:
     DSImpl* impl_;
 };

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/nsec_47.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/nsec_47.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/nsec_47.cc Wed Feb 24 02:05:19 2010
@@ -89,6 +89,16 @@
 
 NSEC::NSEC(InputBuffer& buffer, size_t rdata_len)
 {
+    size_t pos = buffer.getPosition();
+    Name nextname(buffer);
+    rdata_len -= (buffer.getPosition() - pos);
+
+    vector<uint8_t> typebits;
+    for (int i = 0; i < rdata_len; i++) {
+        typebits.push_back(buffer.readUint8());
+    }
+
+    impl_ = new NSECImpl(nextname, typebits);
 }
 
 NSEC::NSEC(const NSEC& source) :
@@ -121,13 +131,13 @@
     int len = 0;
     s << impl_->nextname_;
     for (int i = 0; i < impl_->typebits_.size(); i += len) {
-        if (i + 2 <= impl_->typebits_.size()) {
-            throw ("Invalid NSEC Rdata");
+        if (i + 2 > impl_->typebits_.size()) {
+            dns_throw(InvalidRdataText, "Invalid NSEC Rdata");
         }
         int window = impl_->typebits_[i];
         len = impl_->typebits_[i + 1];
-        if (len > 0 && len <= 32) {
-            throw ("Invalid NSEC Rdata");
+        if (len < 0 || len >= 32) {
+            dns_throw(InvalidRdataText, "Invalid NSEC Rdata");
         }
         i += 2;
         for (int j = 0; j < len; j++) {

Modified: branches/each-ds/src/lib/dns/cpp/rdata/generic/rrsig_46.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata/generic/rrsig_46.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata/generic/rrsig_46.cc Wed Feb 24 02:05:19 2010
@@ -14,13 +14,15 @@
 
 // $Id$
 
+#include <string>
+#include <iomanip>
 #include <iostream>
-#include <string>
 #include <sstream>
 #include <vector>
 
 #include "base64.h"
 #include "buffer.h"
+#include "dnstime.h"
 #include "messagerenderer.h"
 #include "name.h"
 #include "rrtype.h"
@@ -37,44 +39,12 @@
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE
 
-namespace {
-inline uint32_t
-convertDNSSECTime(const string time_txt)
-{
-    istringstream iss(time_txt);
-
-    uint32_t timeval;
-    iss >> timeval;
-
-    // right now, we don't support the YYYYMMDDHHmmSS format for
-    // expire/inception
-    if (iss.bad() || iss.fail() || !iss.eof()) {
-        int year, month, day, hour, minute, second;
-        if (sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
-                   &year, &month, &day, &hour, &minute, &second) != 6) {
-            dns_throw(InvalidRdataText, "Invalid RRSIG Time format");
-        }
-
-        // reformat the date so that strptime() can parse it
-        ostringstream s;
-        s << year << " " << month << " " << day << " "
-          << hour << " " << minute << " " << second;
-
-        struct tm time;
-        strptime(s.str().c_str(), "%Y %m %d %H %M %S", &time);
-        timeval = mktime(&time);
-    }
-
-    return (timeval);
-}
-} // end namespace
-
 struct RRSIGImpl {
     // straightforward representation of RRSIG RDATA fields
     RRSIGImpl(const RRType& covered, uint8_t algorithm, uint8_t labels,
               uint32_t originalttl, uint32_t timeexpire, uint32_t timeinception,
               uint16_t keyid, const Name& signer,
-              const vector<char>& signature) :
+              const vector<uint8_t>& signature) :
         covered_(covered), algorithm_(algorithm), labels_(labels),
         originalttl_(originalttl), timeexpire_(timeexpire),
         timeinception_(timeinception), keyid_(keyid), signer_(signer),
@@ -89,7 +59,7 @@
     uint32_t timeinception_;
     uint16_t keyid_;
     const Name signer_;
-    const vector<char> signature_;
+    const vector<uint8_t> signature_;
 };
 
 RRSIG::RRSIG(const string& rrsig_str) :
@@ -115,10 +85,10 @@
         dns_throw(InvalidRdataText, "RRSIG labels out of range");
     }
 
-    uint32_t timeexpire = convertDNSSECTime(expire_txt);
-    uint32_t timeinception = convertDNSSECTime(inception_txt);
-
-    vector<char> signature;
+    uint32_t timeexpire = DNSSECTimeFromText(expire_txt);
+    uint32_t timeinception = DNSSECTimeFromText(inception_txt);
+
+    vector<uint8_t> signature;
     decodeBase64(signaturebuf.str(), signature);
 
     impl_ = new RRSIGImpl(RRType(covered_txt), algorithm, labels,
@@ -156,12 +126,16 @@
 string
 RRSIG::toText() const
 {
+    string expire, inception;
+    DNSSECTimeToText(impl_->timeexpire_, expire);
+    DNSSECTimeToText(impl_->timeinception_, inception);
+
     return (impl_->covered_.toText() +
             " " + boost::lexical_cast<string>(static_cast<int>(impl_->algorithm_))
             + " " + boost::lexical_cast<string>(static_cast<int>(impl_->labels_))
             + " " + boost::lexical_cast<string>(impl_->originalttl_)
-            + " " + boost::lexical_cast<string>(impl_->timeexpire_)
-            + " " + boost::lexical_cast<string>(impl_->timeinception_)
+            + " " + expire
+            + " " + inception
             + " " + boost::lexical_cast<string>(impl_->keyid_)
             + " " + impl_->signer_.toText()
             + " " + encodeBase64(impl_->signature_));

Modified: branches/each-ds/src/lib/dns/cpp/rdata_unittest.cc
==============================================================================
--- branches/each-ds/src/lib/dns/cpp/rdata_unittest.cc (original)
+++ branches/each-ds/src/lib/dns/cpp/rdata_unittest.cc Wed Feb 24 02:05:19 2010
@@ -52,11 +52,15 @@
     static const uint8_t wiredata_cname2[];
     static const uint8_t wiredata_txt[];
     static const generic::NS rdata_ns, rdata_ns2;
-    static const generic::SOA rdata_soa;
+    static const generic::SOA rdata_soa, rdata_soa2;
     static const generic::CNAME rdata_cname, rdata_cname2;
+    static const generic::DNAME rdata_dname, rdata_dname2;
     static const generic::MX rdata_mx;
     static const generic::TXT rdata_txt;
-    static const generic::TXT rdata_txt_quoated;
+    static const generic::TXT rdata_txt_quoted;
+    static const generic::NSEC rdata_nsec;
+    static const generic::DNSKEY rdata_dnskey;
+    static const generic::DS rdata_ds;
 };
 
 const in::A RdataTest::rdata_in_a("192.0.2.1");
@@ -68,9 +72,21 @@
                                         2010012601, 3600, 300, 3600000, 1200);
 const generic::CNAME RdataTest::rdata_cname("cn.example.com");
 const generic::CNAME RdataTest::rdata_cname2("cn2.example.com");
+// DNAME test uses the same data as CNAME test, for simplicity
+const generic::DNAME RdataTest::rdata_dname("cn.example.com");
+const generic::DNAME RdataTest::rdata_dname2("cn2.example.com");
 const generic::MX RdataTest::rdata_mx(10, Name("mx.example.com"));
 const generic::TXT RdataTest::rdata_txt("Test String");
-const generic::TXT RdataTest::rdata_txt_quoated("\"Test String\"");
+const generic::TXT RdataTest::rdata_txt_quoted("\"Test String\"");
+
+string nsec_txt("www2.isc.org. CNAME RRSIG NSEC");
+const generic::NSEC RdataTest::rdata_nsec(nsec_txt);
+
+string dnskey_txt("257 3 5 BEAAAAOhHQDBrhQbtphgq2wQUpEQ5t4DtUHxoMVFu2hWLDMvoOMRXjGrhhCeFvAZih7yJHf8ZGfW6hd38hXG/xylYCO6Krpbdojwx8YMXLA5/kA+u50WIL8ZR1R6KTbsYVMf/Qx5RiNbPClw+vT+U8eXEJmO20jIS1ULgqy347cBB1zMnnz/4LJpA0da9CbKj3A254T515sNIMcwsB8/2+2E63/zZrQzBkj0BrN/9Bexjpiks3jRhZatEsXn3dTy47R09Uix5WcJt+xzqZ7+ysyLKOOedS39Z7SDmsn2eA0FKtQpwA6LXeG2w+jxmw3oA8lVUgEf/rzeC/bByBNsO70aEFTd");
+const generic::DNSKEY RdataTest::rdata_dnskey(dnskey_txt);
+
+string ds_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D5F0EB5C777586DE18DA6B5");
+const generic::DS RdataTest::rdata_ds(ds_txt);
 
 const uint8_t RdataTest::wiredata_in_a[] = { 192, 0, 2, 1 };
 const uint8_t RdataTest::wiredata_in_aaaa[] = {
@@ -365,7 +381,17 @@
 
 TEST_F(RdataTest, createFromText_MX)
 {
-    //TBD
+    EXPECT_EQ(0, rdata_mx.compare(generic::MX("10 mx.example.com.")));
+}
+
+TEST_F(RdataTest, getMXName)
+{
+    EXPECT_EQ(Name("mx.example.com"), rdata_mx.getMXName());
+}
+
+TEST_F(RdataTest, getMXPref)
+{
+    EXPECT_EQ(10, rdata_mx.getMXPref());
 }
 
 TEST_F(RdataTest, createFromWire_MX)
@@ -416,7 +442,7 @@
 
 TEST_F(RdataTest, createFromText_TXT)
 {
-    EXPECT_EQ(0, rdata_txt.compare(rdata_txt_quoated));
+    EXPECT_EQ(0, rdata_txt.compare(rdata_txt_quoted));
 }
 
 TEST_F(RdataTest, createFromWire_TXT)
@@ -509,20 +535,94 @@
     EXPECT_EQ(Name("cn.example.com."), rdata_cname.getCname());
 }
 
+TEST_F(RdataTest, createFromText_DNAME)
+{
+    EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("cn.example.com")));
+    // explicitly add a trailing dot.  should be the same RDATA.
+    EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("cn.example.com.")));
+    // should be case sensitive.
+    EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("CN.EXAMPLE.COM")));
+    // RDATA of a class-independent type should be recognized for any
+    // "unknown" class.
+    EXPECT_EQ(0, rdata_dname.compare(*createRdata(RRType("DNAME"),
+                                                  RRClass(65000),
+                                                  "cn.example.com")));
+}
+
+TEST_F(RdataTest, createFromWire_DNAME)
+{
+    // Note we're using the CNAME fromwire test file
+    EXPECT_EQ(0, rdata_dname.compare(
+                  *rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                        "testdata/rdata_cname_fromWire")));
+    // RDLENGTH is too short
+    EXPECT_THROW(rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                      "testdata/rdata_cname_fromWire", 18),
+                 InvalidRdataLength);
+    // RDLENGTH is too long
+    EXPECT_THROW(rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                      "testdata/rdata_cname_fromWire", 36),
+                 InvalidRdataLength);
+    // incomplete name.  the error should be detected in the name constructor
+    EXPECT_THROW(rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                      "testdata/rdata_cname_fromWire", 71),
+                 IncompleteName);
+
+    EXPECT_EQ(0, generic::DNAME("cn2.example.com").compare(
+                  *rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                        "testdata/rdata_cname_fromWire", 55)));
+    EXPECT_THROW(*rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
+                                       "testdata/rdata_cname_fromWire", 63),
+                 InvalidRdataLength);
+}
+
+TEST_F(RdataTest, toWireBuffer_DNAME)
+{
+    // using CNAME wiredata
+    rdata_dname.toWire(obuffer);
+    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+                        obuffer.getData(), obuffer.getLength(),
+                        wiredata_cname, sizeof(wiredata_cname));
+}
+
+TEST_F(RdataTest, toWireRenderer_DNAME)
+{
+    // using CNAME wiredata
+    rdata_dname.toWire(renderer);
+    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+                        obuffer.getData(), obuffer.getLength(),
+                        wiredata_cname, sizeof(wiredata_cname));
+    rdata_dname2.toWire(renderer);
+    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+                        obuffer.getData(), obuffer.getLength(),
+                        wiredata_cname2, sizeof(wiredata_cname2));
+}
+
+TEST_F(RdataTest, toText_DNAME)
+{
+    EXPECT_EQ("cn.example.com.", rdata_dname.toText());
+}
+
+TEST_F(RdataTest, getDname_DNAME)
+{
+    EXPECT_EQ(Name("cn.example.com."), rdata_dname.getDname());
+}
+
 TEST_F(RdataTest, fromText_RRSIG)
 {
-    string rrsig_txt("A 5 4 43200 1264801134 191145710 8496 isc.org. "
+    string rrsig_txt("A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
                      "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
                      "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
                      "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
                      "f49t+sXKPzbipN9g+s1ZPiIyofc=");
     generic::RRSIG rdata_rrsig(rrsig_txt);
     EXPECT_EQ(rrsig_txt, rdata_rrsig.toText());
+
 }
 
 TEST_F(RdataTest, toWireRenderer_RRSIG)
 {
-    string rrsig_txt("A 5 4 43200 1264801134 191145710 8496 isc.org. "
+    string rrsig_txt("A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
                      "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
                      "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
                      "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
@@ -531,4 +631,60 @@
     rdata_rrsig.toWire(renderer);
 }
 
-}
+TEST_F(RdataTest, toText_DNSKEY)
+{
+    EXPECT_EQ(dnskey_txt, rdata_dnskey.toText());
+}
+
+TEST_F(RdataTest, createFromWire_DNSKEY)
+{
+    EXPECT_EQ(0, rdata_dnskey.compare(
+                  *rdataFactoryFromFile(RRType("DNSKEY"), RRClass("IN"),
+                                        "testdata/rdata_dnskey_fromWire")));
+}
+
+TEST_F(RdataTest, getID_DNSKEY)
+{
+    EXPECT_EQ(12892, rdata_dnskey.getID());
+}
+
+TEST_F(RdataTest, getAlg_DNSKEY)
+{
+    EXPECT_EQ(5, rdata_dnskey.getAlg());
+}
+
+TEST_F(RdataTest, getFlags_DNSKEY)
+{
+    EXPECT_EQ(257, rdata_dnskey.getFlags());
+}
+
+TEST_F(RdataTest, toText_DS)
+{
+    EXPECT_EQ(ds_txt, rdata_ds.toText());
+}
+
+TEST_F(RdataTest, createFromWire_DS)
+{
+    EXPECT_EQ(0, rdata_ds.compare(
+                  *rdataFactoryFromFile(RRType("DS"), RRClass("IN"),
+                                        "testdata/rdata_ds_fromWire")));
+}
+
+TEST_F(RdataTest, getID_DS)
+{
+    EXPECT_EQ(12892, rdata_ds.getID());
+}
+
+TEST_F(RdataTest, toText_NSEC)
+{
+    EXPECT_EQ(nsec_txt, rdata_nsec.toText());
+}
+
+TEST_F(RdataTest, createFromWire_NSEC)
+{
+    EXPECT_EQ(0, rdata_nsec.compare(
+                  *rdataFactoryFromFile(RRType("NSEC"), RRClass("IN"),
+                                        "testdata/rdata_nsec_fromWire")));
+}
+
+}




More information about the bind10-changes mailing list