parameters: (self, size=-1)
docstring: Read and return up to size bytes, where size is an int.
  
      Args:
        size: Maximum number of bytes to read. As a convenience, if size is
          unspecified or -1, all bytes until EOF are returned.
  
      Returns:
        Bytes read. An empty bytes object is returned if the stream is already at
        EOF. None is returned if no data is available at the moment.
  
      Raises:
        TinkError if there was a permanent error.
        ValueError if the file is closed.
docstring_summary: Read and return up to size bytes, where size is an int.
docstring_tokens: Read and return up to size bytes where size is an int .
function: def read(self, size=-1) -> Optional[bytes]:
      """Read and return up to size bytes, where size is an int.
  
      Args:
        size: Maximum number of bytes to read. As a convenience, if size is
          unspecified or -1, all bytes until EOF are returned.
  
      Returns:
        Bytes read. An empty bytes object is returned if the stream is already at
        EOF. None is returned if no data is available at the moment.
  
      Raises:
        TinkError if there was a permanent error.
        ValueError if the file is closed.
      """
      if self.closed:  # pylint:disable=using-constant-test
        raise ValueError('read on closed file.')
      if size == 0:
        return bytes()
      if self._matching_stream:
        return self._matching_stream.read(size)
      # if self._matching_stream is not set, we are currently reading from
      # self._attempting_stream but no data has been read successfully yet.
      while True:
        try:
          data = self._attempting_stream.read(size)
          if data is None:
            # No data at the moment. Not clear if decryption was successful.
            # Try again with the same stream next time.
            return None
          # Any value other than None means that decryption was successful.
          # (b'' indicates that the plaintext is an empty string.)
          self._matching_stream = self._attempting_stream
          self._attempting_stream = None
          self._ciphertext_source.disable_rewind()
          return data
        except core.TinkError:
          if not self._remaining_primitives:
            raise core.TinkError(
                'No matching key found for the ciphertext in the stream')
          # Try another key.
          self._ciphertext_source.rewind()
          self._attempting_stream = self._next_decrypting_stream()
function_tokens: def read ( self , size = - 1 ) -> Optional [ bytes ] : if self . closed : # pylint:disable=using-constant-test raise ValueError ( 'read on closed file.' ) if size == 0 : return bytes ( ) if self . _matching_stream : return self . _matching_stream . read ( size ) # if self._matching_stream is not set, we are currently reading from # self._attempting_stream but no data has been read successfully yet. while True : try : data = self . _attempting_stream . read ( size ) if data is None : # No data at the moment. Not clear if decryption was successful. # Try again with the same stream next time. return None # Any value other than None means that decryption was successful. # (b'' indicates that the plaintext is an empty string.) self . _matching_stream = self . _attempting_stream self . _attempting_stream = None self . _ciphertext_source . disable_rewind ( ) return data except core . TinkError : if not self . _remaining_primitives : raise core . TinkError ( 'No matching key found for the ciphertext in the stream' ) # Try another key. self . _ciphertext_source . rewind ( ) self . _attempting_stream = self . _next_decrypting_stream ( )