Browse Source

[trac117] cleanup for the helper function, documented it.

JINMEI Tatuya 14 years ago
parent
commit
cf0dac64cd

+ 4 - 2
src/lib/dns/rdata/generic/detail/nsec_bitmap.cc

@@ -27,12 +27,14 @@ namespace generic {
 namespace detail {
 namespace detail {
 namespace nsec {
 namespace nsec {
 void
 void
-buildRRTypeBitmap(const char* const rrtype_name,
-                  const size_t total_len, vector<uint8_t>& typebits)
+checkRRTypeBitmaps(const char* const rrtype_name,
+                   const vector<uint8_t>& typebits)
 {
 {
     int len = 0;
     int len = 0;
     bool first = true;
     bool first = true;
     unsigned int block, lastblock = 0;
     unsigned int block, lastblock = 0;
+    const size_t total_len = typebits.size();
+
     for (int i = 0; i < total_len; i += len) {
     for (int i = 0; i < total_len; i += len) {
         if (i + 2 > total_len) {
         if (i + 2 > total_len) {
             isc_throw(DNSMessageFORMERR, rrtype_name <<
             isc_throw(DNSMessageFORMERR, rrtype_name <<

+ 17 - 2
src/lib/dns/rdata/generic/detail/nsec_bitmap.h

@@ -22,8 +22,23 @@ namespace rdata {
 namespace generic {
 namespace generic {
 namespace detail {
 namespace detail {
 namespace nsec {
 namespace nsec {
-void buildRRTypeBitmap(const char* const rrtype_name,
-                       const size_t total_len, std::vector<uint8_t>& typebits);
+/// Check if a given "type bitmap" for NSEC/NSEC3 is valid.
+///
+/// This helper function checks given wire format data (stored in a
+/// \c std::vector) is a valid type bitmaps used for the NSEC and NSEC3 RRs
+/// according to RFC4034 and RFC5155.  The validation logic is the same
+/// for these two RRs, so a unified check function is provided.
+/// This function is essentially private and is only expected to be called
+/// from the \c NSEC and \c NSEC3 class implementations.
+///
+/// \exception DNSMessageFORMERR The bitmap is not valid.
+///
+/// \param rrtype_name Either "NSEC" or "NSEC3"; used as part of exception
+/// messages.
+/// \param typebits The type bitmaps in wire format.  The size of vector
+/// is the total length of the bitmaps.
+void checkRRTypeBitmaps(const char* const rrtype_name,
+                        const std::vector<uint8_t>& typebits);
 }
 }
 }
 }
 }
 }

+ 1 - 1
src/lib/dns/rdata/generic/nsec3_50.cc

@@ -182,7 +182,7 @@ NSEC3::NSEC3(InputBuffer& buffer, size_t rdata_len) {
 
 
     vector<uint8_t> typebits(rdata_len);
     vector<uint8_t> typebits(rdata_len);
     buffer.readData(&typebits[0], rdata_len);
     buffer.readData(&typebits[0], rdata_len);
-    buildRRTypeBitmap("NSEC3", rdata_len, typebits);
+    checkRRTypeBitmaps("NSEC3", typebits);
 
 
     impl_ = new NSEC3Impl(hashalg, flags, iterations, salt, next, typebits);
     impl_ = new NSEC3Impl(hashalg, flags, iterations, salt, next, typebits);
 }
 }

+ 1 - 1
src/lib/dns/rdata/generic/nsec_47.cc

@@ -105,7 +105,7 @@ NSEC::NSEC(InputBuffer& buffer, size_t rdata_len) {
 
 
     vector<uint8_t> typebits(rdata_len);
     vector<uint8_t> typebits(rdata_len);
     buffer.readData(&typebits[0], rdata_len);
     buffer.readData(&typebits[0], rdata_len);
-    buildRRTypeBitmap("NSEC", rdata_len, typebits);
+    checkRRTypeBitmaps("NSEC", typebits);
 
 
     impl_ = new NSECImpl(nextname, typebits);
     impl_ = new NSECImpl(nextname, typebits);
 }
 }