Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cls, wrapper: primitive_wrapper.PrimitiveWrapper) -> None:
"""Tries to register a PrimitiveWrapper.
Args:
wrapper: A PrimitiveWrapper object.
Raises:
Error if a different wrapper has already been registered for the same
Primitive.
"""
if (wrapper.primitive_class() in cls._wrappers and
type(cls._wrappers[wrapper.primitive_class()]) != type(wrapper)): # pylint: disable=unidiomatic-typecheck
raise tink_error.TinkError(
'A wrapper for primitive {} has already been added.'.format(
wrapper.primitive_class().__name__))
wrapped = wrapper.wrap(
pset_module.PrimitiveSet(wrapper.primitive_class()))
if not isinstance(wrapped, wrapper.primitive_class()):
raise tink_error.TinkError(
'Wrapper for primitive {} generates incompatible primitive of type {}'
.format(wrapper.primitive_class().__name__,
type(wrapped).__name__))
cls._wrappers[wrapper.primitive_class()] = wrapper
Uses the KeyManager and the PrimitiveWrapper objects in the global
registry.Registry
to create the primitive. This function is the most common way of creating a
primitive.
Args:
primitive_class: The class of the primitive.
Returns:
The primitive.
Raises:
tink.TinkError if creation of the primitive fails, for example if
primitive_class cannot be used with this KeysetHandle.
"""
_validate_keyset(self._keyset)
pset = primitive_set.PrimitiveSet(primitive_class)
for key in self._keyset.key:
if key.status == tink_pb2.ENABLED:
primitive = registry.Registry.primitive(key.key_data, primitive_class)
entry = pset.add_primitive(primitive, key)
if key.key_id == self._keyset.primary_key_id:
pset.set_primary(entry)
return registry.Registry.wrap(pset)
read_no_secret_keyset_handle = KeysetHandle.read_no_secret
KeysetReader = keyset_reader.KeysetReader
JsonKeysetReader = keyset_reader.JsonKeysetReader
BinaryKeysetReader = keyset_reader.BinaryKeysetReader
KeysetWriter = keyset_writer.KeysetWriter
JsonKeysetWriter = keyset_writer.JsonKeysetWriter
BinaryKeysetWriter = keyset_writer.BinaryKeysetWriter
Registry = registry.Registry
TinkError = tink_error.TinkError
new_primitive_set = primitive_set.new_primitive_set
PrimitiveSet = primitive_set.PrimitiveSet
PrimitiveWrapper = primitive_wrapper.PrimitiveWrapper
crypto_format = _crypto_format