aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/mac_config_test.cc
diff options
context:
space:
mode:
authortholenst <tholenst@google.com>2018-11-01 07:15:18 -0700
committerCharles Lee <ckl@google.com>2018-11-01 11:48:36 -0700
commit4c30a6aafa75865f93e648906c3c3d0c6b878bc9 (patch)
tree5da8c2311703bee9a18cb4b7a4544f8dfb542eb4 /cc/mac/mac_config_test.cc
parent800107a618ee673956603945c2cea528243a2c29 (diff)
downloadtink-4c30a6aafa75865f93e648906c3c3d0c6b878bc9.tar.gz
Register the primitive wrappers in the registry.
PiperOrigin-RevId: 219629859 GitOrigin-RevId: 7c0038721a0455d91b47072b1cf7b44da4e0f592
Diffstat (limited to 'cc/mac/mac_config_test.cc')
-rw-r--r--cc/mac/mac_config_test.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/cc/mac/mac_config_test.cc b/cc/mac/mac_config_test.cc
index 38e7de96b..8ee6945fa 100644
--- a/cc/mac/mac_config_test.cc
+++ b/cc/mac/mac_config_test.cc
@@ -18,7 +18,9 @@
#include "tink/catalogue.h"
#include "tink/config.h"
+#include "tink/keyset_handle.h"
#include "tink/mac.h"
+#include "tink/mac/mac_key_templates.h"
#include "tink/registry.h"
#include "tink/util/status.h"
#include "gtest/gtest.h"
@@ -100,6 +102,33 @@ TEST_F(MacConfigTest, testRegister) {
EXPECT_EQ(util::error::ALREADY_EXISTS, status.error_code());
}
+// Tests that the MacWrapper has been properly registered and we can wrap
+// primitives.
+TEST_F(MacConfigTest, WrappersRegistered) {
+ ASSERT_TRUE(MacConfig::Register().ok());
+ auto keyset_handle_result =
+ KeysetHandle::GenerateNew(MacKeyTemplates::HmacSha256HalfSizeTag());
+ ASSERT_TRUE(keyset_handle_result.ok());
+
+ auto primitive_set_result =
+ keyset_handle_result.ValueOrDie()->GetPrimitives<Mac>(
+ nullptr);
+ ASSERT_TRUE(primitive_set_result.ok());
+
+ auto primitive_result =
+ Registry::Wrap(std::move(primitive_set_result.ValueOrDie()));
+ ASSERT_TRUE(primitive_result.ok());
+
+ auto mac_result =
+ primitive_result.ValueOrDie()->ComputeMac("verified text");
+ ASSERT_TRUE(mac_result.ok());
+
+ EXPECT_TRUE(primitive_result.ValueOrDie()->VerifyMac(
+ mac_result.ValueOrDie(), "verified text").ok());
+ EXPECT_FALSE(primitive_result.ValueOrDie()->VerifyMac(
+ mac_result.ValueOrDie(), "faked text").ok());
+}
+
} // namespace
} // namespace tink
} // namespace crypto