Parcourir la source

[2124] Don't add trailing space in toText() if fingerprint is empty

Also add some tests.
Mukund Sivaraman il y a 13 ans
Parent
commit
73080d999e

+ 1 - 1
src/lib/dns/rdata/generic/sshfp_44.cc

@@ -128,7 +128,7 @@ string
 SSHFP::toText() const {
     return (lexical_cast<string>(static_cast<int>(algorithm_)) +
             " " + lexical_cast<string>(static_cast<int>(fingerprint_type_)) +
-            " " + encodeHex(fingerprint_));
+            (fingerprint_.size() > 0 ? " " + encodeHex(fingerprint_) : ""));
 }
 
 int

+ 7 - 0
src/lib/dns/tests/rdata_sshfp_unittest.cc

@@ -156,6 +156,13 @@ TEST_F(Rdata_SSHFP_Test, createFromWire) {
 
 TEST_F(Rdata_SSHFP_Test, toText) {
     EXPECT_TRUE(boost::iequals(sshfp_txt, rdata_sshfp.toText()));
+
+    const string sshfp_txt2("2 1");
+    const generic::SSHFP rdata_sshfp2(sshfp_txt2);
+    EXPECT_TRUE(boost::iequals(sshfp_txt2, rdata_sshfp2.toText()));
+
+    const generic::SSHFP rdata_sshfp3("2 1 ");
+    EXPECT_TRUE(boost::iequals(sshfp_txt2, rdata_sshfp3.toText()));
 }
 
 TEST_F(Rdata_SSHFP_Test, toWire) {