# TCTI

class tpm2_pytss.TCTI.PyTCTI(max_size=4096, magic=b'PYTCTI\x00\x00')

  Subclass for implementing a TCTI in Python.

  Extend this object and implement the following methods:
    - def do_transmit(self, command: bytes) -> None

        This method transmits a command buffer to the TPM. This method IS REQUIRED.

    - def do_receive(self, timeout: int) -> bytes:

        This method receives a response from the TPM and returns it. This method IS REQUIRED

    - def do_cancel(self) -> None:

        Cancels an I/O operation with the TPM. This method is OPTIONAL.

    - def do_get_poll_handles(self) -> Optional[Tuple[PollData]]:

        Retrieves PollData objects from the TCTI used for async I/O. This method is OPTIONAL.

    - def do_set_locality(self, locality: int) -> None:

        Sets the locality in which to communicate with the TPM. This method is OPTIONAL.

    - def do_make_sticky(self, handle: int, is_sticky: bool) -> None:

        Makes a handle sticky to persist across client exits with an RM. This method is OPTIONAL.

    - def do_finalize(self) -> None:

        Finalizes a TCTI, this is analogous to close on a file. This method is OPTIONAL.

  Note

  All methods may throw exceptions as needed.

  Parameters:

    - max_size (int) – The size of the response buffer for callers to allocate. Defaults to 4096.

    - magic (bytes) – The magic value for the TCTI, may aid in debugging. Max length is 8, defaults to b”PYTCTI"

  Returns:

    An instance of the PyTCTI class. It’s unusable as is, users should extend it.

  do_cancel()

    Cancels an I/O operation with the TPM. This method is OPTIONAL.

    Raises:

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_finalize()

    Finalizes a TCTI, this is analogous to close on a file. This method is OPTIONAL.

    Note: Native TCTIs do not return anything and thus cannot raise any errors. Python TCTIs MAY raise exceptions across this interface.

    Raises:

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_get_poll_handles()

    Retrieves PollData objects from the TCTI used for async I/O. This method is OPTIONAL.

    Returns:

      The tuple of PollData handles or None.

    Raises:

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_make_sticky(handle, is_sticky)

    Makes a handle sticky to persist across client exits with a Resource Manager. This method is OPTIONAL.

    Note: A sticky object is one a RM doesn’t flush when the client closes their connection.

    Parameters:

      - handle (int) – The TPM handle to make sticky.

      - is_sticky (bool) – True to make sticky, False to make it not sticky.

    Raises:

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_receive(timeout)

    This method receives a response from the TPM and returns it. This method IS REQUIRED.

    Parameters:

      timeout (int) – The timeout in milliseconds to wait for the TPM. Negative values mean wait indefinitely.

    Raises:

      - NotImplementedError – If a subclass has not implemented this.

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_set_locality(locality)

    Sets the locality in which to communicate with the TPM. This method is OPTIONAL.

    Parameters:

      locality (int) – The locality of communication with the TPM.

    Raises:

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

  do_transmit(command)

    This method transmits a command buffer to the TPM. This method IS REQUIRED.

    Parameters:

      command (bytes) – The bytes to send to the TPM.

    Raises:

      - NotImplementedError – If a subclass has not implemented this.

      - Exception – Implementations are free to raise any Exception. Exceptions are retained

      - across the native boundary. –

class tpm2_pytss.TCTI.TCTI(ctx)

  Initialize a TCTI object.

  Initialize a TCTI from a NATIVE instantiated TCTI.

  Parameters:

    ctx (ffi.CData) – A TSS2_TCTI_CONTEXT * variable. This would be returned from a TCTIs initialize or TCTILdr routine.

  Returns:

    An instance of a TCTI.

  cancel(*args, **kwargs)
  finalize(*args, **kwargs)
  get_poll_handles(*args, **kwargs)
  property magic

    Returns the MAGIC string of the TCTI.

    Returns:

      The magic byte string.

  make_sticky(*args, **kwargs)
  receive(*args, **kwargs)
  set_locality(*args, **kwargs)
  transmit(*args, **kwargs)
  property version

    Returns the VERSION number of the TCTI.

    This is the TCTI interface version NOT the release version of the TCTI. Ie if it implements version 1 or version 2 of the spec.

    Returns:

      The TCTI version number.

class tpm2_pytss.TCTILdr.TCTILdr(name=None, conf=None)
  close()
  property conf
  static is_available(name=None)

    Lookup the TCTI and return its availability

    Returns:

      True if the interface is available

  property name
  property name_conf
  classmethod parse(tcti_name_conf)