Parcourir la source

[1575] [1573] corrected the from text constructor so it accepts an empty salt.
not directly related but would be helpful for the purpose of the branch.

JINMEI Tatuya il y a 13 ans
Parent
commit
745181fc6d

+ 4 - 1
src/lib/dns/rdata/generic/nsec3param_51.cc

@@ -67,8 +67,11 @@ NSEC3PARAM::NSEC3PARAM(const string& nsec3param_str) :
         isc_throw(InvalidRdataText, "NSEC3PARAM flags out of range");
     }
 
+    const string salt_str = saltbuf.str();
     vector<uint8_t> salt;
-    decodeHex(saltbuf.str(), salt);
+    if (salt_str != "-") { // "-" means an empty salt, no need to touch vector
+        decodeHex(saltbuf.str(), salt);
+    }
 
     impl_ = new NSEC3PARAMImpl(hashalg, flags, iterations, salt);
 }

+ 13 - 2
src/lib/dns/tests/rdata_nsec3param_unittest.cc

@@ -40,9 +40,20 @@ using namespace isc::dns::rdata;
 
 namespace {
 class Rdata_NSEC3PARAM_Test : public RdataTest {
-    // there's nothing to specialize
+public:
+    Rdata_NSEC3PARAM_Test() : nsec3param_txt("1 0 1 D399EAAB") {}
+    const string nsec3param_txt;
 };
-string nsec3param_txt("1 0 1 D399EAAB");
+
+TEST_F(Rdata_NSEC3PARAM_Test, fromText) {
+    // With a salt
+    EXPECT_EQ(1, generic::NSEC3PARAM(nsec3param_txt).getHashalg());
+    EXPECT_EQ(0, generic::NSEC3PARAM(nsec3param_txt).getFlags());
+    // (salt is checked in the toText test)
+
+    // With an empty salt
+    EXPECT_EQ(0, generic::NSEC3PARAM("1 0 0 -").getSalt().size());
+}
 
 TEST_F(Rdata_NSEC3PARAM_Test, toText) {
     const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);