Skip to content

Tpm2 stream

tpm2_stream

Module that contains utility classes to help marshal and un-marshal date to/from the TPM.

Tpm2StreamElement

Tpm2 Stream Element.

__init__

__init__() -> Tpm2StreamElement

Init an empty Tpm2StreamElement.

get_size

get_size() -> int

The size of this structure when marshalled.

Tpm2StreamPrimitive

Tpm2 Stream Primitive.

Attributes:

Name Type Description
size

size of the primitive. 1, 2, 4, or 8 bytes

value

Value of primitive

__init__

__init__(size: int, value: str) -> Tpm2StreamPrimitive

Init a primitive value.

Parameters:

Name Type Description Default
size int

1, 2, 4, or 8 bytes

required
value str

Value to stream.

required

marshal

marshal() -> bytes

Serializes the Tpm2 primitive.

Returns:

Type Description
str

string representing packed data as bytes (i.e. b'\x01\x00\x03')

TPM2_COMMAND_HEADER

Tpm2 Command header.

Attributes:

Name Type Description
tag

The Tag

code

The Code

size

The size of the code

__init__

__init__(
    tag: str, size: str, code: str
) -> TPM2_COMMAND_HEADER

Init a Tpm2 command.

update_size

update_size(size: int) -> None

Update size of the whole command.

marshal

marshal() -> str

Serializes the Tpm2 command header.

Returns:

Type Description
str

string representing packed data as bytes (i.e. b'\x01\x00\x03')

TPM2B

Tpm2 B.

__init__

__init__(data: str) -> TPM2B

Inits the object.

update_data

update_data(data: str) -> None

Updates the data attribute.

marshal

marshal() -> str

Serializes the Tpm2B object.

Returns:

Type Description
str

string representing packed data as bytes (i.e. b'\x01\x00\x03')

Tpm2CommandStream

Tpm2 Command Stream.

__init__

__init__(
    tag: str, size: int, code: str
) -> Tpm2CommandStream

Inits a Tpm2 Command stream object.

get_size

get_size() -> int

Returns the stream size.

add_element

add_element(element: Tpm2StreamElement) -> None

Adds an element to the stream list.

get_stream

get_stream() -> str

Serializes the Header + elements.

Returns:

Type Description
str

string representing packed data as bytes (i.e. b'\x01\x00\x03')