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.
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;
/// 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
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
}
};
+// 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) {
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")));