Commit dcf58b78 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac781] some trivial changes:

- editorial/style fixes
- constify things in trivial cases
- catch exceptions by const reference
parent f4f11a9b
......@@ -60,7 +60,7 @@ class CryptoImpl {
public:
CryptoImpl() {}
~CryptoImpl() {};
private:
Botan::LibraryInitializer _botan_init;
};
......@@ -68,7 +68,7 @@ private:
Crypto::Crypto() {
try {
impl_ = new CryptoImpl();
} catch (Botan::Exception ex) {
} catch (const Botan::Exception& ex) {
isc_throw(InitializationError, ex.what());
}
}
......@@ -86,7 +86,7 @@ public:
try {
hash = Botan::get_hash(
getBotanHashAlgorithmName(hash_algorithm));
} catch (const Botan::Algorithm_Not_Found) {
} catch (const Botan::Algorithm_Not_Found&) {
isc_throw(isc::crypto::UnsupportedAlgorithm,
"Unknown hash algorithm: " + hash_algorithm);
}
......@@ -113,7 +113,7 @@ public:
~HMACImpl() { delete hmac_; }
size_t getOutputLength() {
size_t getOutputLength() const {
return (hmac_->OUTPUT_LENGTH);
}
......@@ -177,8 +177,8 @@ HMAC::~HMAC() {
}
size_t
HMAC::getOutputLength() {
return impl_->getOutputLength();
HMAC::getOutputLength() const {
return (impl_->getOutputLength());
}
void
......
......@@ -114,7 +114,7 @@ public:
/// \brief Returns the output size of the digest
///
/// \return output size of the digest
size_t getOutputLength();
size_t getOutputLength() const;
/// \brief Add data to digest
///
......
......@@ -28,8 +28,10 @@ namespace {
ASSERT_EQ(data1[i], data2[i]);
}
}
void checkBuffer(const OutputBuffer& buf, uint8_t *data, size_t len) {
void checkBuffer(const OutputBuffer& buf, const uint8_t* data,
size_t len)
{
ASSERT_EQ(len, buf.getLength());
checkData(static_cast<const uint8_t*>(buf.getData()), data, len);
}
......@@ -39,7 +41,7 @@ namespace {
const void* secret,
size_t secret_len,
const HMAC::HashAlgorithm hash_algorithm,
uint8_t* expected_hmac,
const uint8_t* expected_hmac,
size_t hmac_len) {
OutputBuffer data_buf(data.size());
data_buf.writeData(data.c_str(), data.size());
......@@ -72,7 +74,7 @@ namespace {
const void* secret,
size_t secret_len,
const HMAC::HashAlgorithm hash_algorithm,
uint8_t* expected_hmac,
const uint8_t* expected_hmac,
size_t hmac_len) {
OutputBuffer data_buf(data.size());
data_buf.writeData(data.c_str(), data.size());
......@@ -103,7 +105,7 @@ namespace {
const void* secret,
size_t secret_len,
const HMAC::HashAlgorithm hash_algorithm,
uint8_t* expected_hmac,
const uint8_t* expected_hmac,
size_t hmac_len) {
HMAC hmac_sign(secret, secret_len, hash_algorithm);
hmac_sign.update(data.c_str(), data.size());
......@@ -123,11 +125,11 @@ namespace {
const void* secret,
size_t secret_len,
const HMAC::HashAlgorithm hash_algorithm,
uint8_t* expected_hmac,
const uint8_t* expected_hmac,
size_t hmac_len) {
HMAC hmac_sign(secret, secret_len, hash_algorithm);
hmac_sign.update(data.c_str(), data.size());
uint8_t sig[hmac_len];
hmac_sign.sign(sig, hmac_len);
......@@ -145,7 +147,7 @@ namespace {
const void* secret,
size_t secret_len,
const HMAC::HashAlgorithm hash_algorithm,
uint8_t* expected_hmac,
const uint8_t* expected_hmac,
size_t hmac_len) {
doHMACTestConv(data, secret, secret_len, hash_algorithm,
expected_hmac, hmac_len);
......@@ -169,7 +171,7 @@ TEST(CryptoTest, HMAC_MD5_RFC2202_SIGN) {
0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8,
0x15, 0x8b, 0xfc, 0x9d };
doHMACTest("Hi There", secret, 16, HMAC::MD5, hmac_expected, 16);
uint8_t hmac_expected2[] = { 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0,
0xb5, 0x03, 0xea, 0xa8, 0x6e, 0x31,
0x0a, 0x5d, 0xb7, 0x38 };
......
......@@ -21,6 +21,6 @@ int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::crypto::Crypto crypto;
return (RUN_ALL_TESTS());
}
......@@ -63,27 +63,27 @@ TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name,
}
TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) {
size_t pos = str.find(':');
if (pos == 0 || pos == str.npos || pos == str.size()-1) {
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 {
Name key_name(str.substr(0, pos));
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);
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));
algo_name = Name(str.substr(pos2 + 1));
} else {
pos2 = str.size() - pos;
}
std::string secret_str = str.substr(pos + 1, pos2 - pos - 1);
const std::string secret_str = str.substr(pos + 1, pos2 - pos - 1);
if (algo_name != HMACMD5_NAME() &&
algo_name != HMACSHA1_NAME() &&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment