aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/mac_config_test.cc
diff options
context:
space:
mode:
authortholenst <tholenst@google.com>2019-07-31 13:21:17 -0700
committerCopybara-Service <copybara-worker@google.com>2019-07-31 13:21:49 -0700
commitd73d7be49eef974ddf283d23e9fad0fca6d566d5 (patch)
tree07152e3e400f8f15e868087948c96166c1a5bc4d /cc/mac/mac_config_test.cc
parent9e9100ce6117dbd24afa4e51deebf74c6b7f9eef (diff)
downloadtink-d73d7be49eef974ddf283d23e9fad0fca6d566d5.tar.gz
C++/Objc Tink: Remove building the RegistryConfig protos.
These are not needed anymore, since we simply register all key managers directly; they were only needed for catalogue support. PiperOrigin-RevId: 260986202
Diffstat (limited to 'cc/mac/mac_config_test.cc')
-rw-r--r--cc/mac/mac_config_test.cc52
1 files changed, 13 insertions, 39 deletions
diff --git a/cc/mac/mac_config_test.cc b/cc/mac/mac_config_test.cc
index 5b32cebce..0a007a72c 100644
--- a/cc/mac/mac_config_test.cc
+++ b/cc/mac/mac_config_test.cc
@@ -16,13 +16,15 @@
#include "tink/mac/mac_config.h"
+#include "gtest/gtest.h"
#include "tink/config.h"
#include "tink/keyset_handle.h"
#include "tink/mac.h"
+#include "tink/mac/hmac_key_manager.h"
#include "tink/mac/mac_key_templates.h"
#include "tink/registry.h"
#include "tink/util/status.h"
-#include "gtest/gtest.h"
+#include "tink/util/test_matchers.h"
#include "tink/util/test_util.h"
namespace crypto {
@@ -30,6 +32,8 @@ namespace tink {
namespace {
using ::crypto::tink::test::DummyMac;
+using ::crypto::tink::test::IsOk;
+using ::crypto::tink::test::StatusIs;
class MacConfigTest : public ::testing::Test {
protected:
@@ -38,44 +42,14 @@ class MacConfigTest : public ::testing::Test {
}
};
-TEST_F(MacConfigTest, testBasic) {
- std::string hmac_key_type = "type.googleapis.com/google.crypto.tink.HmacKey";
- std::string aes_cmac_key_type =
- "type.googleapis.com/google.crypto.tink.AesCmacKey";
- auto& config = MacConfig::Latest();
-
- EXPECT_EQ(2, MacConfig::Latest().entry_size());
- EXPECT_EQ("TinkMac", config.entry(0).catalogue_name());
- EXPECT_EQ("Mac", config.entry(0).primitive_name());
- EXPECT_EQ(hmac_key_type, config.entry(0).type_url());
- EXPECT_EQ(true, config.entry(0).new_key_allowed());
- EXPECT_EQ(0, config.entry(0).key_manager_version());
-
- EXPECT_EQ("TinkMac", config.entry(1).catalogue_name());
- EXPECT_EQ("Mac", config.entry(1).primitive_name());
- EXPECT_EQ(aes_cmac_key_type, config.entry(1).type_url());
- EXPECT_EQ(true, config.entry(1).new_key_allowed());
- EXPECT_EQ(0, config.entry(1).key_manager_version());
-
- // No key manager before registration.
- auto manager_result = Registry::get_key_manager<Mac>(hmac_key_type);
- EXPECT_FALSE(manager_result.ok());
- EXPECT_EQ(util::error::NOT_FOUND, manager_result.status().error_code());
-
- // No key manager before registration.
- manager_result = Registry::get_key_manager<Mac>(aes_cmac_key_type);
- EXPECT_FALSE(manager_result.ok());
- EXPECT_EQ(util::error::NOT_FOUND, manager_result.status().error_code());
-
- // Registration of standard key types works.
- auto status = MacConfig::Register();
- EXPECT_TRUE(status.ok()) << status;
- manager_result = Registry::get_key_manager<Mac>(hmac_key_type);
- EXPECT_TRUE(manager_result.ok()) << manager_result.status();
- EXPECT_TRUE(manager_result.ValueOrDie()->DoesSupport(hmac_key_type));
- manager_result = Registry::get_key_manager<Mac>(aes_cmac_key_type);
- EXPECT_TRUE(manager_result.ok()) << manager_result.status();
- EXPECT_TRUE(manager_result.ValueOrDie()->DoesSupport(aes_cmac_key_type));
+TEST_F(MacConfigTest, Basic) {
+ EXPECT_THAT(
+ Registry::get_key_manager<Mac>(HmacKeyManager().get_key_type()).status(),
+ StatusIs(util::error::NOT_FOUND));
+ MacConfig::Register();
+ EXPECT_THAT(
+ Registry::get_key_manager<Mac>(HmacKeyManager().get_key_type()).status(),
+ IsOk());
}
// Tests that the MacWrapper has been properly registered and we can wrap