policy

class tpm2_pytss.policy(policy, hash_alg)[source]

Initialize policy object.

Parameters:
  • policy (Union(bytes, str]) – The JSON policy to calculate or execute.

  • hash_alg (TPM2_ALG) – The hash algorithm to use for policy calculations.

Returns:

An instance of the policy object.

This class implements the policy part of the TCG TSS 2.0 JSON Data Types and Policy Language Specification.

The specification can be found at https://trustedcomputinggroup.org/resource/tcg-tss-json/

calculate()[source]

Calculate the policy

Raises:

TSS2_Exception

close()[source]

Finalize the policy instance

property description

The policy description.

Type:

bytes

execute(esys_ctx, session)[source]

Executes the policy

Parameters:
  • esys_ctx (ESAPI) – The ESAPI instance to use during policy execution.

  • session (ESYS_TR) – The policy session to use during execution.

Raises:

TSS2_Exception or any possible exception from a callback function.

get_calculated_digest()[source]

Get the digest of the calculated policy

Returns:

The digest as a TPM2B_DIGEST.

Raises:

TSS2_Exception

get_calculated_json()[source]

Get the calculated policy as JSON

Returns:

The calculated JSON policy as bytes

Raises:

TSS2_Exception

property hash_alg

The hash algorithm to be used during policy calculcation.

Type:

TPM2_ALG

property policy

The JSON policy.

Type:

bytes

set_callback(callback_type, callback)[source]

Set callback for policy calculaction or execution

Parameters:
  • callback_type (policy_cb_types) – Which callback to set or unset.

  • callback (Union[None, Callable]) – The callback function to call, or None to remove the callback.

Raises:

ValueError