def _validate_primitive_set(pset: core.PrimitiveSet): # TODO(juerg): also validate that there is a primary for entries in pset.all(): for entry in entries: if (entry.output_prefix_type != tink_pb2.RAW and entry.output_prefix_type != tink_pb2.TINK): raise core.TinkError('unsupported OutputPrefixType')
def __init__(self, primitive_set: core.PrimitiveSet, ciphertext_source: BinaryIO, associated_data: bytes): """Create a new _DecryptingStreamWrapper. Args: primitive_set: The primitive set of StreamingAead primitives. ciphertext_source: A readable file-like object from which ciphertext bytes will be read. associated_data: The associated data to use for decryption. """ super(_DecryptingStreamWrapper, self).__init__() if not ciphertext_source.readable(): raise ValueError('ciphertext_source must be readable') self._ciphertext_source = _rewindable_input_stream.RewindableInputStream( ciphertext_source) self._associated_data = associated_data self._matching_stream = None self._remaining_primitives = [ entry.primitive for entry in primitive_set.raw_primitives()] self._attempting_stream = self._next_decrypting_stream()
def wrap(self, primitives_set: core.PrimitiveSet) -> prf.Prf: if primitives_set.primary(): return primitives_set.primary().primitive else: return _InvalidPrf()