Skip to content
Snippets Groups Projects
Commit 569fc192 authored by tholenst's avatar tholenst Committed by Copybara-Service
Browse files

Add a "config_util" class with a method "CreateTinkKeyTypeEntry"

I plan to remove the catalogue (in upcoming changes). For this, I need to untangle some of the dependencies, and this is easiest if I add a new BUILD target which only creates a Tink Key Type.

PiperOrigin-RevId: 260116920
parent 86f786c2
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,17 @@ cc_library(
],
)
cc_library(
name = "config_util",
srcs = ["config_util.cc"],
hdrs = ["config_util.h"],
include_prefix = "tink",
strip_include_prefix = "/cc",
deps = [
"//proto:config_cc_proto",
],
)
# tests
cc_test(
......@@ -43,3 +54,13 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "config_util_test",
size = "small",
srcs = ["config_util_test.cc"],
deps = [
":config_util",
"@com_google_googletest//:gtest_main",
],
)
......@@ -16,6 +16,15 @@ tink_cc_library(
tink::proto::config_cc_proto
)
tink_cc_library(
NAME config_util
SRCS
config_util.cc
config_util.h
DEPS
tink::proto::config_cc_proto
)
# tests
tink_cc_test(
......@@ -34,3 +43,11 @@ tink_cc_test(
tink::core::streaming_aead
tink::util::status
)
tink_cc_test(
NAME config_util_test
SRCS config_util_test.cc
DEPS
tink::config::config_util
gmock
)
// 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 "tink/config/config_util.h"
namespace crypto {
namespace tink {
google::crypto::tink::KeyTypeEntry CreateTinkKeyTypeEntry(
const std::string& catalogue_name, const std::string& primitive_name,
const std::string& key_proto_name, int key_manager_version,
bool new_key_allowed) {
std::string prefix = "type.googleapis.com/google.crypto.tink.";
google::crypto::tink::KeyTypeEntry entry;
entry.set_catalogue_name(catalogue_name);
entry.set_primitive_name(primitive_name);
entry.set_type_url(prefix.append(key_proto_name));
entry.set_key_manager_version(key_manager_version);
entry.set_new_key_allowed(new_key_allowed);
return entry;
}
} // namespace tink
} // namespace crypto
// 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.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef TINK_CONFIG_CONFIG_UTIL_H_
#define TINK_CONFIG_CONFIG_UTIL_H_
#include "proto/config.pb.h"
namespace crypto {
namespace tink {
google::crypto::tink::KeyTypeEntry CreateTinkKeyTypeEntry(
const std::string& catalogue_name, const std::string& primitive_name,
const std::string& key_proto_name, int key_manager_version,
bool new_key_allowed);
} // namespace tink
} // namespace crypto
#endif // TINK_CONFIG_CONFIG_UTIL_H_
// 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 "tink/config/config_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq;
namespace crypto {
namespace tink {
TEST(CreateKeyTypeEntry, Simple) {
google::crypto::tink::KeyTypeEntry entry = CreateTinkKeyTypeEntry(
"catalogue", "primitive_name", "key_proto_name", 12, true);
EXPECT_THAT(entry.catalogue_name(), Eq("catalogue"));
}
} // namespace tink
} // namespace crypto
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment