aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/mac_config_test.cc
diff options
context:
space:
mode:
authortholenst <tholenst@google.com>2019-02-18 00:45:25 -0800
committerTink Team <noreply@google.com>2019-02-18 15:35:57 -0500
commit1aa204abeee8b0fe52ea3d4d0457ccf65e44824f (patch)
treed2c9bd2f1b8009ded72d697fb8789c6cf58efdf4 /cc/mac/mac_config_test.cc
parent222092b77fefd760a87f202dab0e969a5c6f88c9 (diff)
downloadtink-1aa204abeee8b0fe52ea3d4d0457ccf65e44824f.tar.gz
Make keyset_handle->GetPrimitives() private.
Given that now keyset_handle has a function GetPrimitive, there seems to be no reason for it to expose GetPrimitives() anymore. Nobody should have called it, since the PrimitiveSet<> is not in the public APIs anyhow (and unless I'm missing something there's nothing you can give the result to immediately either or with auto). The only exception would be if someone implemented their own factory, but I don't think there are factories at the moment. PiperOrigin-RevId: 234436305 GitOrigin-RevId: f51581b2812c5ee03c7087acb63274eb6a2dc785
Diffstat (limited to 'cc/mac/mac_config_test.cc')
-rw-r--r--cc/mac/mac_config_test.cc32
1 files changed, 18 insertions, 14 deletions
diff --git a/cc/mac/mac_config_test.cc b/cc/mac/mac_config_test.cc
index 8ee6945fa..8695a01fb 100644
--- a/cc/mac/mac_config_test.cc
+++ b/cc/mac/mac_config_test.cc
@@ -24,11 +24,14 @@
#include "tink/registry.h"
#include "tink/util/status.h"
#include "gtest/gtest.h"
+#include "tink/util/test_util.h"
namespace crypto {
namespace tink {
namespace {
+using ::crypto::tink::test::DummyMac;
+
class DummyMacCatalogue : public Catalogue<Mac> {
public:
DummyMacCatalogue() {}
@@ -106,27 +109,28 @@ TEST_F(MacConfigTest, testRegister) {
// 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());
+ google::crypto::tink::Keyset::Key key;
+ key.set_status(google::crypto::tink::KeyStatusType::ENABLED);
+ key.set_key_id(1234);
+ key.set_output_prefix_type(google::crypto::tink::OutputPrefixType::RAW);
+ auto primitive_set = absl::make_unique<PrimitiveSet<Mac>>();
+ primitive_set->set_primary(
+ primitive_set->AddPrimitive(absl::make_unique<DummyMac>("dummy"), key)
+ .ValueOrDie());
- auto primitive_result =
- Registry::Wrap(std::move(primitive_set_result.ValueOrDie()));
- ASSERT_TRUE(primitive_result.ok());
+ auto primitive_result = Registry::Wrap(std::move(primitive_set));
+ ASSERT_TRUE(primitive_result.ok()) << primitive_result.status();
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());
+ EXPECT_TRUE(DummyMac("dummy")
+ .VerifyMac(mac_result.ValueOrDie(), "verified text")
+ .ok());
+ EXPECT_FALSE(
+ DummyMac("dummy").VerifyMac(mac_result.ValueOrDie(), "faked text").ok());
}
} // namespace