aboutsummaryrefslogtreecommitdiff
path: root/cc/registry.h
diff options
context:
space:
mode:
authorBartosz Przydatek <przydatek@google.com>2017-10-04 20:37:11 +0200
committerThai Duong <thaidn@google.com>2017-10-06 13:15:01 -0700
commit8e3310220ecf9b0127c765ffce08e164b360b588 (patch)
treef25ca952d3b04539f503427207e1ea3c13e6faef /cc/registry.h
parent6256d7cd45f13aad065e49572d1ef53ae9f78d5c (diff)
downloadtink-8e3310220ecf9b0127c765ffce08e164b360b588.tar.gz
Accepting multiple registration of same key manager in C++ registry.
Change-Id: I0b1d48d5a29e7d12df805f1cc28aab07d2d9affb ORIGINAL_AUTHOR=Bartosz Przydatek <przydatek@google.com> GitOrigin-RevId: 44205bea27caded86c765b480a47fb78b8a72eca
Diffstat (limited to 'cc/registry.h')
-rw-r--r--cc/registry.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/cc/registry.h b/cc/registry.h
index 95ff17100..98f38af59 100644
--- a/cc/registry.h
+++ b/cc/registry.h
@@ -227,14 +227,18 @@ crypto::tink::util::Status Registry::RegisterKeyManager(
std::lock_guard<std::mutex> lock(maps_mutex_);
auto curr_manager = type_to_manager_map_.find(type_url.ToString());
if (curr_manager != type_to_manager_map_.end()) {
- return ToStatusF(crypto::tink::util::error::ALREADY_EXISTS,
- "A manager for type '%s' has been already registered.",
- type_url.ToString().c_str());
+ auto existing = static_cast<KeyManager<P>*>(curr_manager->second.get());
+ if (typeid(*existing).name() != typeid(*manager).name()) {
+ return ToStatusF(crypto::tink::util::error::ALREADY_EXISTS,
+ "A manager for type '%s' has been already registered.",
+ type_url.ToString().c_str());
+ }
+ } else {
+ type_to_manager_map_.insert(
+ std::make_pair(type_url.ToString(), std::move(entry)));
+ type_to_primitive_map_.insert(
+ std::make_pair(type_url.ToString(), typeid(P).name()));
}
- type_to_manager_map_.insert(
- std::make_pair(type_url.ToString(), std::move(entry)));
- type_to_primitive_map_.insert(
- std::make_pair(type_url.ToString(), typeid(P).name()));
return crypto::tink::util::Status::OK;
}