[svn] commit: r1119 - in /branches/each-nsec3/src/lib/dns/cpp: ./ rdata/generic/ tests/ tests/testdata/
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Mar 5 00:15:03 UTC 2010
Author: each
Date: Fri Mar 5 00:15:03 2010
New Revision: 1119
Log:
checkpoint:
- completed NSEC3 and NSEC3PARAM rdata implementations
- fixed a base32 conversion bug
Added:
branches/each-nsec3/src/lib/dns/cpp/tests/rdata_nsec3param_unittest.cc
Modified:
branches/each-nsec3/src/lib/dns/cpp/base32.cc
branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.cc
branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.h
branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.cc
branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.h
branches/each-nsec3/src/lib/dns/cpp/tests/Makefile.am
branches/each-nsec3/src/lib/dns/cpp/tests/base32_unittest.cc
branches/each-nsec3/src/lib/dns/cpp/tests/testdata/rdata_nsec3_fromWire2
Modified: branches/each-nsec3/src/lib/dns/cpp/base32.cc
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/base32.cc (original)
+++ branches/each-nsec3/src/lib/dns/cpp/base32.cc Fri Mar 5 00:15:03 2010
@@ -83,7 +83,7 @@
}
digit = ((binary.at(pos + 2) << 1) & 0x1e) |
- ((binary.at(pos + 2) >> 7) & 0x01);
+ ((binary.at(pos + 3) >> 7) & 0x01);
buf[4] = base32hex[digit];
digit = (binary.at(pos + 3) >> 2) & 0x1f;
Modified: branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.cc
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.cc (original)
+++ branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.cc Fri Mar 5 00:15:03 2010
@@ -125,28 +125,36 @@
dns_throw(InvalidRdataLength, "NSEC3 too short");
}
- size_t pos = buffer.getPosition();
-
uint8_t hash = buffer.readUint8();
uint8_t flags = buffer.readUint8();
uint16_t iterations = buffer.readUint16();
rdata_len -= 4;
uint8_t saltlen = buffer.readUint8();
+ --rdata_len;
+
+ if (rdata_len < saltlen) {
+ dns_throw(InvalidRdataLength, "NSEC3 salt too short");
+ }
+
vector<uint8_t> salt(saltlen);
buffer.readData(&salt[0], saltlen);
- rdata_len -= saltlen + 1;
+ rdata_len -= saltlen;
uint8_t nextlen = buffer.readUint8();
+ --rdata_len;
+
+ if (rdata_len < nextlen) {
+ dns_throw(InvalidRdataLength, "NSEC3 next hash too short");
+ }
+
vector<uint8_t> next(nextlen);
buffer.readData(&next[0], nextlen);
- rdata_len -= nextlen + 1;
-
- // rdata_len must be sufficiently large to hold non empty bitmap.
- if (rdata_len <= buffer.getPosition() - pos) {
- dns_throw(InvalidRdataLength, "NSEC3 too short");
- }
- rdata_len -= (buffer.getPosition() - pos);
+ rdata_len -= nextlen;
+
+ if (rdata_len == 0) {
+ dns_throw(InvalidRdataLength, "NSEC3 type bitmap too short");
+ }
// FIXIT: we cannot naively copy the data because the bitmaps have
// semantics and other part of this class assumes they are valid.
@@ -293,5 +301,25 @@
}
}
+uint8_t
+NSEC3::getHash() const {
+ return impl_->hash_;
+}
+
+uint8_t
+NSEC3::getFlags() const {
+ return impl_->flags_;
+}
+
+uint16_t
+NSEC3::getIterations() const {
+ return impl_->iterations_;
+}
+
+vector<uint8_t>
+NSEC3::getSalt() const {
+ return impl_->salt_;
+}
+
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
Modified: branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.h
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.h (original)
+++ branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3_50.h Fri Mar 5 00:15:03 2010
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <string>
+#include <vector>
#include "name.h"
#include "rrtype.h"
@@ -40,6 +41,12 @@
// END_COMMON_MEMBERS
NSEC3& operator=(const NSEC3& source);
~NSEC3();
+
+ uint8_t getHash() const;
+ uint8_t getFlags() const;
+ uint16_t getIterations() const;
+ std::vector<uint8_t> getSalt() const;
+
private:
NSEC3Impl* impl_;
};
Modified: branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.cc
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.cc (original)
+++ branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.cc Fri Mar 5 00:15:03 2010
@@ -74,16 +74,22 @@
NSEC3PARAM::NSEC3PARAM(InputBuffer& buffer, size_t rdata_len)
{
- if (rdata_len < 5) {
+ if (rdata_len < 4) {
dns_throw(InvalidRdataLength, "NSEC3PARAM too short");
}
uint8_t hash = buffer.readUint8();
uint8_t flags = buffer.readUint8();
- uint16_t iterations = buffer.readUint32();
+ uint16_t iterations = buffer.readUint16();
+ rdata_len -= 4;
+
uint8_t saltlen = buffer.readUint8();
-
- rdata_len -= 5;
+ --rdata_len;
+
+ if (rdata_len < saltlen) {
+ dns_throw(InvalidRdataLength, "NSEC3PARAM salt too short");
+ }
+
vector<uint8_t> salt(saltlen);
buffer.readData(&salt[0], saltlen);
@@ -170,9 +176,24 @@
}
}
+uint8_t
+NSEC3PARAM::getHash() const {
+ return impl_->hash_;
+}
+
+uint8_t
+NSEC3PARAM::getFlags() const {
+ return impl_->flags_;
+}
+
uint16_t
-NSEC3PARAM::getTag() const {
- return impl_->hash_;
+NSEC3PARAM::getIterations() const {
+ return impl_->iterations_;
+}
+
+vector<uint8_t>
+NSEC3PARAM::getSalt() const {
+ return impl_->salt_;
}
// END_RDATA_NAMESPACE
Modified: branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.h
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.h (original)
+++ branches/each-nsec3/src/lib/dns/cpp/rdata/generic/nsec3param_51.h Fri Mar 5 00:15:03 2010
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <string>
+#include <vector>
#include "name.h"
#include "rrtype.h"
@@ -44,7 +45,10 @@
///
/// Specialized methods
///
- uint16_t getTag() const;
+ uint8_t getHash() const;
+ uint8_t getFlags() const;
+ uint16_t getIterations() const;
+ std::vector<uint8_t> getSalt() const;
private:
NSEC3PARAMImpl* impl_;
};
Modified: branches/each-nsec3/src/lib/dns/cpp/tests/Makefile.am
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/tests/Makefile.am (original)
+++ branches/each-nsec3/src/lib/dns/cpp/tests/Makefile.am Fri Mar 5 00:15:03 2010
@@ -23,6 +23,7 @@
run_unittests_SOURCES += rdata_ds_unittest.cc
run_unittests_SOURCES += rdata_nsec_unittest.cc
run_unittests_SOURCES += rdata_nsec3_unittest.cc
+run_unittests_SOURCES += rdata_nsec3param_unittest.cc
run_unittests_SOURCES += rdata_rrsig_unittest.cc
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
Modified: branches/each-nsec3/src/lib/dns/cpp/tests/base32_unittest.cc
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/tests/base32_unittest.cc (original)
+++ branches/each-nsec3/src/lib/dns/cpp/tests/base32_unittest.cc Fri Mar 5 00:15:03 2010
@@ -35,6 +35,16 @@
Base32Test() {}
};
+TEST_F(Base32Test, reversibility)
+{
+ vector<uint8_t> result;
+// const string input("H9RSFB7FPF2L8HG35CMPC765TDK23RP6");
+ const string input("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+ decodeBase32(input, result);
+ string output = encodeBase32(result);
+ EXPECT_EQ(input, output);
+}
+
TEST_F(Base32Test, decode1)
{
vector<uint8_t> result;
Modified: branches/each-nsec3/src/lib/dns/cpp/tests/testdata/rdata_nsec3_fromWire2
==============================================================================
--- branches/each-nsec3/src/lib/dns/cpp/tests/testdata/rdata_nsec3_fromWire2 (original)
+++ branches/each-nsec3/src/lib/dns/cpp/tests/testdata/rdata_nsec3_fromWire2 Fri Mar 5 00:15:03 2010
@@ -2,8 +2,8 @@
# NSEC3 RDATA with a bogus RDLEN (too short)
#
-# RDLENGTH, 33 bytes (should be 39)
-00 21
+# RDLENGTH, 29 bytes (should be 39)
+00 1e
# NSEC3 record:
# 1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 NS SOA RRSIG DNSKEY NSEC3PARAM
More information about the bind10-changes
mailing list