Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcti/py: initial commit #2749

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Feb 14, 2024

  1. tcti/py: initial commit

    Implmenet a TCTI module that will allow folks to write TCTIs in Python3.
    This will allow for more crazy and complex TCTI scenarios without having
    to re-write everyones stacks to use tpm2-pytss.
    
    Example Commandline:
    ```bash
    PYTHONPATH=$HOME tpm2_getcap --verbose --tcti=py:pytctitabrmd properties-fixed
    ```
    
    Example TCTI:
    For the ultimate in mind-bending: C -> Python -> C and back for
    efficiency :-p.
    
    ```python3
    from tpm2_pytss import TCTILdr
    from typing import Union
    
    class MyPyTCTI(object):
        def __init__(self, args: str):
            c = args.split(":", maxsplit=1)
            mod = c[0]
            args = c[1] if len(c) > 1 else "None"
            print(f"PYTHON: Initializing TCTI Ldr with mod: {mod} args: {args}")
            self._tcti = TCTILdr(mod, args)
    
        @Property
        def magic(self) -> Union[bytes, int]:
            # Optional Method
            print("PYTHON magic")
            return 42
    
        def receive(self, timeout: int) -> bytes:
            print("PYTHON receive")
            return self._tcti.receive(timeout=timeout)
    
        def transmit(self, data: bytes) -> None:
            print("PYTHON transmit")
            return self._tcti.receive(timeout=timeout)
    
    def tcti_init(args: str) -> MyPyTCTI:
        print(f"PYTHON tcti_init called with: {args}")
        return MyPyTCTI(args)
    
    ```
    
    Signed-off-by: Bill Roberts <[email protected]>
    williamcroberts committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    5cc69ec View commit details
    Browse the repository at this point in the history