Browse Source

[1638] unified NSEC3PARAM::toWire() methods, fixing a small bug for empty salt.

JINMEI Tatuya 13 years ago
parent
commit
cfb3f053d8

+ 14 - 10
src/lib/dns/rdata/generic/nsec3param_51.cc

@@ -154,22 +154,26 @@ NSEC3PARAM::toText() const {
             " " + (impl_->salt_.empty() ? "-" : encodeHex(impl_->salt_)));
 }
 
+template <typename OUTPUT_TYPE>
+void
+toWireHelper(const NSEC3PARAMImpl& impl, OUTPUT_TYPE& output) {
+    output.writeUint8(impl.hashalg_);
+    output.writeUint8(impl.flags_);
+    output.writeUint16(impl.iterations_);
+    output.writeUint8(impl.salt_.size());
+    if (!impl.salt_.empty()) {
+        output.writeData(&impl.salt_[0], impl.salt_.size());
+    }
+}
+
 void
 NSEC3PARAM::toWire(OutputBuffer& buffer) const {
-    buffer.writeUint8(impl_->hashalg_);
-    buffer.writeUint8(impl_->flags_);
-    buffer.writeUint16(impl_->iterations_);
-    buffer.writeUint8(impl_->salt_.size());
-    buffer.writeData(&impl_->salt_[0], impl_->salt_.size());
+    toWireHelper(*impl_, buffer);
 }
 
 void
 NSEC3PARAM::toWire(AbstractMessageRenderer& renderer) const {
-    renderer.writeUint8(impl_->hashalg_);
-    renderer.writeUint8(impl_->flags_);
-    renderer.writeUint16(impl_->iterations_);
-    renderer.writeUint8(impl_->salt_.size());
-    renderer.writeData(&impl_->salt_[0], impl_->salt_.size());
+    toWireHelper(*impl_, renderer);
 }
 
 int

+ 1 - 1
src/lib/dns/tests/rdata_nsec3param_like_unittest.cc

@@ -223,7 +223,7 @@ toWireCheck(RRType rrtype, OUTPUT_TYPE& output, const string& data_file) {
                         output.getLength(), &data[0], data.size());
 }
 
-TYPED_TEST(NSEC3PARAMLikeTest, DISABLED_toWire) {
+TYPED_TEST(NSEC3PARAMLikeTest, toWire) {
     // normal case
     toWireCheck(this->getType(), this->renderer,
                 this->getWireFilePrefix() + "fromWire1");