Stay organized with collections
Save and categorize content based on your preferences.
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.
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. ↩
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-14 UTC."],[[["The Registry in Tink is a global entity responsible for generating new keys and primitives, but it is intended for internal use only and is slated for removal."],["The Registry forwards calls from `getPrimitive()` to objects that create keys and primitives, and these objects must be registered for the process to work."],["It's essential to explicitly register the primitives you intend to use (e.g., `MacConfig.register()`), to ensure your code works consistently and doesn't rely on the unpredictable behavior of other libraries."],["Relying on other libraries to register primitives can lead to unexpected code breakage if the library's registration practices change, making it crucial to self-manage registrations."]]],["The Registry is a global entity in Tink for generating keys and primitives, but it's slated for removal and should not be directly accessed. `getPrimitive()` calls are forwarded to the Registry, which then creates the correct object, if registered. It is crucial to register the primitives one intends to use directly, using method like `MacConfig.register()`, because relying on library registration leads to code fragility and unwanted dependencies. The class is considered for removal.\n"]]