aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/mac_config_test.cc
diff options
context:
space:
mode:
authorBartosz Przydatek <przydatek@google.com>2017-07-03 17:54:38 +0200
committerThai Duong <thaidn@google.com>2017-07-10 20:32:57 -0700
commitf12db8a65d733a4744e4ea5dab68560bd2e993aa (patch)
tree3bfa0b2bcb64e62078cd62703428775223647ecc /cc/mac/mac_config_test.cc
parenta058c3e2017a7abd0fc1cb35b01c7947e7a4e703 (diff)
downloadtink-f12db8a65d733a4744e4ea5dab68560bd2e993aa.tar.gz
Adding C++ ...Config-classes for primitives.
Change-Id: Ie289cf5a84adf92991e15193f3244c5264ca7ed3 ORIGINAL_AUTHOR=Bartosz Przydatek <przydatek@google.com> GitOrigin-RevId: 0a16afe6c8a506713b043867f697219a02277626
Diffstat (limited to 'cc/mac/mac_config_test.cc')
-rw-r--r--cc/mac/mac_config_test.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/cc/mac/mac_config_test.cc b/cc/mac/mac_config_test.cc
new file mode 100644
index 000000000..5e69234cd
--- /dev/null
+++ b/cc/mac/mac_config_test.cc
@@ -0,0 +1,59 @@
+// Copyright 2017 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+#include "cc/registry.h"
+#include "cc/mac/mac_config.h"
+#include "cc/util/status.h"
+#include "gtest/gtest.h"
+
+
+namespace crypto {
+namespace tink {
+namespace {
+
+class MacConfigTest : public ::testing::Test {
+};
+
+TEST_F(MacConfigTest, testBasic) {
+ // Registration of standard key types works.
+ auto& registry = Registry::get_default_registry();
+ std::string key_type = "type.googleapis.com/google.crypto.tink.HmacKey";
+ auto manager_result = registry.get_key_manager<Mac>(key_type);
+ EXPECT_FALSE(manager_result.ok());
+ EXPECT_EQ(util::error::NOT_FOUND, manager_result.status().error_code());
+ EXPECT_TRUE(MacConfig::RegisterStandardKeyTypes().ok());
+ manager_result = registry.get_key_manager<Mac>(key_type);
+ EXPECT_TRUE(manager_result.ok()) << manager_result.status();
+ EXPECT_TRUE(manager_result.ValueOrDie()->DoesSupport(key_type));
+
+ // Registration of legacy key types works.
+ EXPECT_TRUE(MacConfig::RegisterLegacyKeyTypes().ok());
+
+ // Registration of individual key managers checks the passed pointer.
+ auto status = MacConfig::RegisterKeyManager(nullptr);
+ EXPECT_FALSE(status.ok());
+}
+
+
+} // namespace
+} // namespace tink
+} // namespace crypto
+
+
+int main(int ac, char* av[]) {
+ testing::InitGoogleTest(&ac, av);
+ return RUN_ALL_TESTS();
+}