How to use the tink.python.aead.aead.Aead function in tink

To help you get started, we’ve selected a few tink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / tink / python / aead / aead_key_manager.py View on Github external
from __future__ import absolute_import
from __future__ import division
from __future__ import google_type_annotations
from __future__ import print_function

from typing import Text

from tink.cc.python import aead as cc_aead
from tink.python.aead import aead
from tink.python.cc.clif import cc_key_manager
from tink.python.core import key_manager
from tink.python.core import tink_error


class _AeadCcToPyWrapper(aead.Aead):
  """Transforms cliffed C++ Aead primitive into a Python primitive."""

  def __init__(self, cc_primitive: cc_aead.Aead):
    self._aead = cc_primitive

  @tink_error.use_tink_errors
  def encrypt(self, plaintext: bytes, associated_data: bytes) -> bytes:
    return self._aead.encrypt(plaintext, associated_data)

  @tink_error.use_tink_errors
  def decrypt(self, plaintext: bytes, associated_data: bytes) -> bytes:
    return self._aead.decrypt(plaintext, associated_data)


def from_cc_registry(type_url: Text) -> key_manager.KeyManager[aead.Aead]:
  return key_manager.KeyManagerCcToPyWrapper(
github google / tink / python / aead / aead_wrapper.py View on Github external
def primitive_class(self) -> Type[aead.Aead]:
    return aead.Aead
github google / tink / python / aead / aead_wrapper.py View on Github external
from __future__ import division
from __future__ import google_type_annotations
from __future__ import print_function

from absl import logging

from typing import Type

from tink.python.aead import aead
from tink.python.core import crypto_format
from tink.python.core import primitive_set
from tink.python.core import primitive_wrapper
from tink.python.core import tink_error


class _WrappedAead(aead.Aead):
  """Implements Aead for a set of Aead primitives."""

  def __init__(self, pset: primitive_set.PrimitiveSet):
    self._primitive_set = pset

  def encrypt(self, plaintext: bytes, associated_data: bytes) -> bytes:
    primary = self._primitive_set.primary()
    return primary.identifier + primary.primitive.encrypt(
        plaintext, associated_data)

  def decrypt(self, ciphertext: bytes, associated_data: bytes) -> bytes:
    if len(ciphertext) > crypto_format.NON_RAW_PREFIX_SIZE:
      prefix = ciphertext[:crypto_format.NON_RAW_PREFIX_SIZE]
      ciphertext_no_prefix = ciphertext[crypto_format.NON_RAW_PREFIX_SIZE:]
      for entry in self._primitive_set.primitive_from_identifier(prefix):
        try:
github google / tink / python / aead / aead_key_manager.py View on Github external
def from_cc_registry(type_url: Text) -> key_manager.KeyManager[aead.Aead]:
  return key_manager.KeyManagerCcToPyWrapper(
      cc_key_manager.AeadKeyManager.from_cc_registry(type_url), aead.Aead,
      _AeadCcToPyWrapper)