diff --git a/hmac.cpp b/hmac.cpp index 319ff8d..eec053e 100644 --- a/hmac.cpp +++ b/hmac.cpp @@ -102,7 +102,7 @@ namespace hmac { digest_size = hmac_hash::SHA512::DIGEST_SIZE; break; default: - return {}; + throw std::invalid_argument("Unsupported hash type"); } // Step 1: Normalize key diff --git a/test_all.cpp b/test_all.cpp index 91e8777..7e2254a 100644 --- a/test_all.cpp +++ b/test_all.cpp @@ -51,6 +51,13 @@ TEST(HMACTest, NullPointersThrow) { EXPECT_THROW(hmac::get_hmac(key, 3, nullptr, 1, hmac::TypeHash::SHA256), std::invalid_argument); } +TEST(HMACTest, InvalidTypeThrows) { + const char* key = "key"; + const char* msg = "abc"; + auto invalid = static_cast(999); + EXPECT_THROW(hmac::get_hmac(key, 3, msg, 3, invalid), std::invalid_argument); +} + TEST(TOTPTest, AtTime) { const std::string totp_key = "12345678901234567890"; uint64_t test_time = 1234567890;