aboutsummaryrefslogtreecommitdiff
path: root/cc/registry.h
diff options
context:
space:
mode:
authorThomas Holenstein <tholenst@google.com>2018-10-04 01:39:04 -0700
committerTink Team <noreply@google.com>2018-10-04 11:47:53 -0700
commit4eacb3ed3c680f978d7beff62921e90be1886a19 (patch)
treec818320e31daab4df38534184c4bdce44254854d /cc/registry.h
parent388d90066e3222167f1de7536bdf48d3b4dd3b5f (diff)
downloadtink-4eacb3ed3c680f978d7beff62921e90be1886a19.tar.gz
Change the functions RegisterCatalogue and RegisterKeyManager so they take unique_ptr instead of raw pointers.
PiperOrigin-RevId: 215701167 GitOrigin-RevId: 7bbbbce6db88dbae15614016f229b6e282e4e50d
Diffstat (limited to 'cc/registry.h')
-rw-r--r--cc/registry.h38
1 files changed, 29 insertions, 9 deletions
diff --git a/cc/registry.h b/cc/registry.h
index 792fb2d5b..302afd4f4 100644
--- a/cc/registry.h
+++ b/cc/registry.h
@@ -65,28 +65,48 @@ class Registry {
// Adding a custom catalogue should be a one-time operation,
// and fails if the given 'catalogue' tries to override
// an existing, different catalogue for the specified name.
+ template <class P>
+ static crypto::tink::util::Status AddCatalogue(
+ const std::string& catalogue_name, std::unique_ptr<Catalogue<P>> catalogue) {
+ return RegistryImpl::GlobalInstance().AddCatalogue<P>(catalogue_name,
+ catalogue.release());
+ }
+
+ // AddCatalogue has the same functionality as the overload which uses a
+ // unique_ptr and which should be preferred.
//
- // Takes ownership of 'catalogue', which must be non-nullptr
- // (in case of failure, 'catalogue' is deleted).
+ // Takes ownership of 'catalogue', which must be non-nullptr (in case of
+ // failure, 'catalogue' is deleted).
template <class P>
+ ABSL_DEPRECATED("Use AddCatalogue with a unique_ptr input instead.")
static crypto::tink::util::Status AddCatalogue(const std::string& catalogue_name,
Catalogue<P>* catalogue) {
- return RegistryImpl::GlobalInstance().AddCatalogue<P>(catalogue_name,
- catalogue);
+ return AddCatalogue(catalogue_name, absl::WrapUnique(catalogue));
}
// Registers the given 'manager' for the key type 'manager->get_key_type()'.
- // Takes ownership of 'manager', which must be non-nullptr.
template <class P>
- static crypto::tink::util::Status RegisterKeyManager(KeyManager<P>* manager,
- bool new_key_allowed) {
- return RegistryImpl::GlobalInstance().RegisterKeyManager(manager,
+ static crypto::tink::util::Status RegisterKeyManager(
+ std::unique_ptr<KeyManager<P>> manager, bool new_key_allowed) {
+ return RegistryImpl::GlobalInstance().RegisterKeyManager(manager.release(),
new_key_allowed);
}
+ // Same functionality as the overload which takes a unique pointer, for
+ // new_key_allowed = true.
template <class P>
+ ABSL_DEPRECATED(
+ "Use RegisterKeyManager with a unique_ptr manager and new_key_allowed = "
+ "true instead.")
static crypto::tink::util::Status RegisterKeyManager(KeyManager<P>* manager) {
- return RegistryImpl::GlobalInstance().RegisterKeyManager(manager);
+ return RegisterKeyManager(absl::WrapUnique(manager), true);
+ }
+
+ template <class P>
+ ABSL_DEPRECATED("Use RegisterKeyManager with a unique_ptr manager instead.")
+ static crypto::tink::util::Status RegisterKeyManager(KeyManager<P>* manager,
+ bool new_key_allowed) {
+ return RegisterKeyManager(absl::WrapUnique(manager), new_key_allowed);
}
// Returns a key manager for the given type_url (if any found).