BIND 10 trac1576, updated. 540d2a66787b2ff57e20a2c99a84d2875dfbcc54 [1576] made DefaultNSEC3HashCreator so an experimental app can use it internally.

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Feb 13 18:00:06 UTC 2012


The branch, trac1576 has been updated
       via  540d2a66787b2ff57e20a2c99a84d2875dfbcc54 (commit)
       via  6d675cbff066b5ee3f1c3bde7aab7dfd0ad1482c (commit)
      from  ecd4db4c298f4f1aae038bc0b42837478fe9910b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 540d2a66787b2ff57e20a2c99a84d2875dfbcc54
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Feb 13 09:59:39 2012 -0800

    [1576] made DefaultNSEC3HashCreator so an experimental app can use it internally.

commit 6d675cbff066b5ee3f1c3bde7aab7dfd0ad1482c
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Feb 13 09:07:54 2012 -0800

    [1576] removed virtual from the InMemoryZoneFinderTest destructor for now

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/tests/memory_datasrc_unittest.cc |    2 +-
 src/lib/dns/nsec3hash.cc                         |   24 +++++++++---------
 src/lib/dns/nsec3hash.h                          |   24 +++++++++++++++++--
 src/lib/dns/tests/nsec3hash_unittest.cc          |   27 ++++++++++++++++++++-
 4 files changed, 59 insertions(+), 18 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/memory_datasrc_unittest.cc b/src/lib/datasrc/tests/memory_datasrc_unittest.cc
index ee8eec1..6212e67 100644
--- a/src/lib/datasrc/tests/memory_datasrc_unittest.cc
+++ b/src/lib/datasrc/tests/memory_datasrc_unittest.cc
@@ -447,7 +447,7 @@ public:
                    boost::bind(setRRset, _1, rrsets.begin()));
     }
 
-    virtual ~InMemoryZoneFinderTest() {
+    ~InMemoryZoneFinderTest() {
         // Make sure we reset the hash creator to the default
         setNSEC3HashCreator(NULL);
     }
diff --git a/src/lib/dns/nsec3hash.cc b/src/lib/dns/nsec3hash.cc
index cee504f..159dff3 100644
--- a/src/lib/dns/nsec3hash.cc
+++ b/src/lib/dns/nsec3hash.cc
@@ -143,18 +143,6 @@ NSEC3HashRFC5155::match(const generic::NSEC3PARAM& nsec3param) const {
                   nsec3param.getSalt()));
 }
 
-class DefaultNSEC3HashCreator : public NSEC3HashCreator {
-public:
-    virtual NSEC3Hash* create(const generic::NSEC3PARAM& param) const {
-        return (new NSEC3HashRFC5155(param.getHashalg(), param.getIterations(),
-                                     param.getSalt()));
-    }
-    virtual NSEC3Hash* create(const generic::NSEC3& nsec3) const {
-        return (new NSEC3HashRFC5155(nsec3.getHashalg(), nsec3.getIterations(),
-                                 nsec3.getSalt()));
-    }
-};
-
 // A static pointer that refers to the currently usable creator.
 // Only get/setNSEC3HashCreator are expected to get access to this variable
 // directly.
@@ -186,6 +174,18 @@ NSEC3Hash::create(const generic::NSEC3& nsec3) {
     return (getNSEC3HashCreator()->create(nsec3));
 }
 
+NSEC3Hash*
+DefaultNSEC3HashCreator::create(const generic::NSEC3PARAM& param) const {
+    return (new NSEC3HashRFC5155(param.getHashalg(), param.getIterations(),
+                                 param.getSalt()));
+}
+
+NSEC3Hash*
+DefaultNSEC3HashCreator::create(const generic::NSEC3& nsec3) const {
+    return (new NSEC3HashRFC5155(nsec3.getHashalg(), nsec3.getIterations(),
+                                 nsec3.getSalt()));
+}
+
 void
 setNSEC3HashCreator(const NSEC3HashCreator* new_creator) {
     creator = new_creator;
diff --git a/src/lib/dns/nsec3hash.h b/src/lib/dns/nsec3hash.h
index b743948..2056708 100644
--- a/src/lib/dns/nsec3hash.h
+++ b/src/lib/dns/nsec3hash.h
@@ -170,9 +170,12 @@ public:
 /// The two main methods named \c create() correspond to the static factory
 /// methods of \c NSEC3Hash of the same name.
 ///
-/// By default, the library uses a builtin creator implementation.  The
-/// \c setNSEC3HashCreator() function can be used to replace it with a user
-/// defined version.
+/// By default, the library uses the \c DefaultNSEC3HashCreator creator.
+/// The \c setNSEC3HashCreator() function can be used to replace it with a
+/// user defined version.  For such customization purposes as implementing
+/// experimental new hash algorithms, the application may internally want to
+/// use the \c DefaultNSEC3HashCreator in general cases while creating a
+/// customized type of \c NSEC3Hash object for that particular hash algorithm.
 ///
 /// The creator objects are generally expected to be stateless; they will
 /// only encapsulate the factory logic.  The \c create() methods are declared
@@ -209,6 +212,21 @@ public:
         const = 0;
 };
 
+/// \brief The default NSEC3Hash creator.
+///
+/// This derived class implements the \c NSEC3HashCreator interfaces for
+/// the standard NSEC3 hash calculator as defined in RFC5155.  The library
+/// will use this creator by default, so normal applications don't have to
+/// be aware of this class at all.  This class is publicly visible for the
+/// convenience of special applications that want to customize the creator
+/// behavior for a particular type of parameters while preserving the default
+/// behavior for others.
+class DefaultNSEC3HashCreator : public NSEC3HashCreator {
+public:
+    virtual NSEC3Hash* create(const rdata::generic::NSEC3PARAM& param) const;
+    virtual NSEC3Hash* create(const rdata::generic::NSEC3& nsec3) const;
+};
+
 /// \brief The registrar of \c NSEC3HashCreator.
 ///
 /// This function sets or resets the system-wide \c NSEC3HashCreator that
diff --git a/src/lib/dns/tests/nsec3hash_unittest.cc b/src/lib/dns/tests/nsec3hash_unittest.cc
index 3f2dad2..e607c74 100644
--- a/src/lib/dns/tests/nsec3hash_unittest.cc
+++ b/src/lib/dns/tests/nsec3hash_unittest.cc
@@ -160,14 +160,25 @@ class TestNSEC3Hash : public NSEC3Hash {
     }
 };
 
+// This faked creator basically creates the faked calculator regardless of
+// the passed NSEC3PARAM or NSEC3.  But if the most significant bit of flags
+// is set, it will behave like the default creator.
 class TestNSEC3HashCreator : public NSEC3HashCreator {
 public:
-    virtual NSEC3Hash* create(const generic::NSEC3PARAM&) const {
+    virtual NSEC3Hash* create(const generic::NSEC3PARAM& param) const {
+        if ((param.getFlags() & 0x80) != 0) {
+            return (default_creator_.create(param));
+        }
         return (new TestNSEC3Hash);
     }
-    virtual NSEC3Hash* create(const generic::NSEC3&) const {
+    virtual NSEC3Hash* create(const generic::NSEC3& nsec3) const {
+        if ((nsec3.getFlags() & 0x80) != 0) {
+            return (default_creator_.create(nsec3));
+        }
         return (new TestNSEC3Hash);
     }
+private:
+    DefaultNSEC3HashCreator default_creator_;
 };
 
 TEST_F(NSEC3HashTest, setCreator) {
@@ -189,6 +200,18 @@ TEST_F(NSEC3HashTest, setCreator) {
     EXPECT_EQ("00000000000000000000000000000000",
               test_hash->calculate(Name("example")));
 
+    // If we set a special flag big (0x80) on creation, it will act like the
+    // default creator.
+    test_hash.reset(NSEC3Hash::create(generic::NSEC3PARAM(
+                                          "1 128 12 aabbccdd")));
+    EXPECT_EQ("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
+              test_hash->calculate(Name("example")));
+    test_hash.reset(NSEC3Hash::create(generic::NSEC3
+                                      ("1 128 12 aabbccdd " +
+                                       string(nsec3_common))));
+    EXPECT_EQ("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
+              test_hash->calculate(Name("example")));
+
     // Reset the creator to default, and confirm that
     setNSEC3HashCreator(NULL);
     test_hash.reset(NSEC3Hash::create(generic::NSEC3PARAM("1 0 12 aabbccdd")));




More information about the bind10-changes mailing list