summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJelte Jansen <jelte@isc.org>2011-04-19 16:09:30 +0200
committerJelte Jansen <jelte@isc.org>2011-04-19 16:09:30 +0200
commitcf456aa1546145ac403e75535e555d773b39ff20 (patch)
tree46dad2963ac40775b4e91a4deeecaf5e1c952cd6 /src
parent[trac781] constify (diff)
downloadkea-cf456aa1546145ac403e75535e555d773b39ff20.tar.xz
kea-cf456aa1546145ac403e75535e555d773b39ff20.zip
[trac781] apply proposed patch
Diffstat (limited to 'src')
-rw-r--r--src/lib/dns/tsigkey.cc41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/lib/dns/tsigkey.cc b/src/lib/dns/tsigkey.cc
index 4edeca96b8..8d530ae02a 100644
--- a/src/lib/dns/tsigkey.cc
+++ b/src/lib/dns/tsigkey.cc
@@ -63,28 +63,31 @@ TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name,
}
TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
- const size_t pos = str.find(':');
- if (pos == 0 || pos == str.npos || pos == str.size() - 1) {
- // error
- isc_throw(InvalidParameter, "Invalid TSIG key string");
- }
try {
- const Name key_name(str.substr(0, pos));
- Name algo_name("hmac-md5.sig-alg.reg.int");
-
- // optional algorithm part
- size_t pos2 = str.find(':', pos + 1);
- if (pos2 != str.npos) {
- if (pos2 == pos + 1) {
- isc_throw(InvalidParameter, "Invalid TSIG key string");
- }
- algo_name = Name(str.substr(pos2 + 1));
- } else {
- pos2 = str.size() - pos;
+ istringstream iss(str);
+
+ string keyname_str;
+ getline(iss, keyname_str, ':');
+ if (iss.fail() || iss.bad() || iss.eof()) {
+ isc_throw(InvalidParameter, "Invalid TSIG key string: " << str);
+ }
+
+ string secret_str;
+ getline(iss, secret_str, ':');
+ if (iss.fail() || iss.bad()) {
+ isc_throw(InvalidParameter, "Invalid TSIG key string: " << str);
}
- const std::string secret_str = str.substr(pos + 1, pos2 - pos - 1);
+ string algo_str;
+ if (!iss.eof()) {
+ getline(iss, algo_str);
+ }
+ if (iss.fail() || iss.bad()) {
+ isc_throw(InvalidParameter, "Invalid TSIG key string: " << str);
+ }
+ 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()) {
@@ -95,7 +98,7 @@ TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
vector<uint8_t> secret;
decodeBase64(secret_str, secret);
- impl_ = new TSIGKeyImpl(key_name, algo_name, &secret[0],
+ impl_ = new TSIGKeyImpl(Name(keyname_str), algo_name, &secret[0],
secret.size());
} catch (const Exception& e) {
// 'reduce' the several types of exceptions name parsing and