Browse Source

[trac781] renamed test and refactored duplicate initialization code

Jelte Jansen 14 years ago
parent
commit
f137e0fa3a
3 changed files with 12 additions and 8 deletions
  1. 1 1
      src/lib/dns/tests/tsigkey_unittest.cc
  2. 10 6
      src/lib/dns/tsigkey.cc
  3. 1 1
      src/lib/dns/tsigkey.h

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

@@ -227,7 +227,7 @@ TEST_F(TSIGKeyRingTest, findFromSome) {
               keyring.find(Name("noexist.example")).key);
 }
 
-TEST(TSIGTest, TSIGKeyFromToString) {
+TEST(TSIGStringTest, TSIGKeyFromToString) {
     TSIGKey k1 = TSIGKey("test.example:MSG6Ng==:hmac-md5.sig-alg.reg.int");
     TSIGKey k2 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.");
     TSIGKey k3 = TSIGKey("test.example:MSG6Ng==");

+ 10 - 6
src/lib/dns/tsigkey.cc

@@ -26,6 +26,14 @@
 
 using namespace std;
 
+namespace {
+    bool isValidAlgorithmName(const isc::dns::Name& name) {
+        return (name == isc::dns::TSIGKey::HMACMD5_NAME() ||
+                name == isc::dns::TSIGKey::HMACSHA1_NAME() ||
+                name == isc::dns::TSIGKey::HMACSHA256_NAME());
+    }
+}
+
 namespace isc {
 namespace dns {
 struct
@@ -47,9 +55,7 @@ TSIGKey::TSIGKeyImpl {
 TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name,
                  const void* secret, size_t secret_len) : impl_(NULL)
 {
-    if (algorithm_name != HMACMD5_NAME() &&
-        algorithm_name != HMACSHA1_NAME() &&
-        algorithm_name != HMACSHA256_NAME()) {
+    if (!isValidAlgorithmName(algorithm_name)) {
         isc_throw(InvalidParameter, "Unknown TSIG algorithm is specified: " <<
                   algorithm_name);
     }
@@ -88,9 +94,7 @@ TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
 
         const Name algo_name(algo_str.empty() ? "hmac-md5.sig-alg.reg.int" :
                              algo_str);
-        if (algo_name != HMACMD5_NAME() &&
-            algo_name != HMACSHA1_NAME() &&
-            algo_name != HMACSHA256_NAME()) {
+        if (!isValidAlgorithmName(algo_name)) {
             isc_throw(InvalidParameter, "Unknown TSIG algorithm is specified: " <<
                       algo_name);
         }

+ 1 - 1
src/lib/dns/tsigkey.h

@@ -107,7 +107,7 @@ public:
     /// invalid.
     ///
     /// \param str The string to make a TSIGKey from
-    TSIGKey(const std::string& str);
+    explicit TSIGKey(const std::string& str);
 
     /// \brief The copy constructor.
     ///