Browse Source

[2387] Update NSEC3PARAM string RDATA constructor to use MasterLexer

Also adjust tests.
Mukund Sivaraman 12 years ago
parent
commit
fb7adf34e9

+ 20 - 11
src/lib/dns/rdata/generic/nsec3param_51.cc

@@ -49,24 +49,33 @@ struct NSEC3PARAMImpl {
 NSEC3PARAM::NSEC3PARAM(const std::string& nsec3param_str) :
     impl_(NULL)
 {
-    istringstream iss(nsec3param_str);
-    vector<uint8_t> salt;
-    const ParseNSEC3ParamResult params =
-        parseNSEC3ParamText("NSEC3PARAM", nsec3param_str, iss, salt);
-
-    if (!iss.eof()) {
-        isc_throw(InvalidRdataText, "Invalid NSEC3PARAM (redundant text): "
-                  << nsec3param_str);
+    try {
+        std::istringstream ss(nsec3param_str);
+        MasterLexer lexer;
+        lexer.pushSource(ss);
+
+        constructFromLexer(lexer);
+
+        if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
+            isc_throw(InvalidRdataText,
+                      "Extra input text for NSEC3PARAM: " << nsec3param_str);
+        }
+    } catch (const MasterLexer::LexerError& ex) {
+        isc_throw(InvalidRdataText,
+                  "Failed to construct NSEC3PARAM from '" << nsec3param_str
+                  << "': " << ex.what());
     }
-
-    impl_ = new NSEC3PARAMImpl(params.algorithm, params.flags,
-                               params.iterations, salt);
 }
 
 NSEC3PARAM::NSEC3PARAM(MasterLexer& lexer, const Name*, MasterLoader::Options,
                        MasterLoaderCallbacks&) :
     impl_(NULL)
 {
+    constructFromLexer(lexer);
+}
+
+void
+NSEC3PARAM::constructFromLexer(MasterLexer& lexer) {
     vector<uint8_t> salt;
     const ParseNSEC3ParamResult params =
         parseNSEC3ParamFromLexer("NSEC3PARAM", lexer, salt);

+ 4 - 0
src/lib/dns/rdata/generic/nsec3param_51.h

@@ -21,6 +21,7 @@
 #include <dns/rrtype.h>
 #include <dns/rrttl.h>
 #include <dns/rdata.h>
+#include <dns/master_lexer.h>
 
 // BEGIN_HEADER_GUARD
 
@@ -47,7 +48,10 @@ public:
     uint8_t getFlags() const;
     uint16_t getIterations() const;
     const std::vector<uint8_t>& getSalt() const;
+
 private:
+    void constructFromLexer(isc::dns::MasterLexer& lexer);
+
     NSEC3PARAMImpl* impl_;
 };
 

+ 5 - 3
src/lib/dns/tests/rdata_nsec3param_unittest.cc

@@ -58,12 +58,14 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) {
 TEST_F(Rdata_NSEC3PARAM_Test, toText) {
     const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
     EXPECT_EQ(nsec3param_txt, rdata_nsec3param.toText());
+
+    // Garbage space at the end should be ok. RFC5155 only forbids
+    // whitespace within the salt field, but any whitespace afterwards
+    // should be fine.
+    EXPECT_NO_THROW(generic::NSEC3PARAM("1 1 1 D399EAAB "));
 }
 
 TEST_F(Rdata_NSEC3PARAM_Test, badText) {
-    // garbage space at the end
-    EXPECT_THROW(generic::NSEC3PARAM("1 1 1 D399EAAB "),
-                 InvalidRdataText);
 }
 
 TEST_F(Rdata_NSEC3PARAM_Test, createFromWire) {