Registry

Starting with the basics, here is an informal definition of Registry:

But:

That being said, it may be useful to understand this class in order to work with Tink efficiently for the time being.

What happens when you call getPrimitive() on a keyset handle? It forwards your call to the Registry1, which contains objects with concrete methods to create keys and primitives, such as an AesGcm key or a ChunkedMac instance. The Registry's task is to forward the call to the correct object. This only works if the object is registered, which is why it's important to always register the primitives you are going to use.

But what if I use a library that already registered the primitives I need?

That's precisely the problem. And one of the reasons Registry is being removed. Because in this case your code works only until the library authors decide to not register that primitive anymore. At this point your code breaks, and the reason is non-obvious and confusing. So always register what you use. For example, if you intend you use MAC in your Java code, you should do the following in the setup phase:

MacConfig.register()

This code ensures that all the necessary objects are registered in the necessary places for you to use the MAC primitive.

There is one more side to this problem. Some of your dependencies may register things you actually don't need and would prefer to not depend on. This is another reason to remove the global Registry.


  1. to the global singleton instance of the class Registry, to be precise. We use the name "Registry" for both, the class and the singleton, interchangeably.