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

really drop python<=3.7 support #577

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/libtss2_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if not os.path.isabs(PATH):
PATH = os.path.join(os.getcwd(), PATH)

print("adding path: {}".format(PATH))
print(f"adding path: {PATH}")
sys.path.insert(0, PATH)
from prepare_headers import prepare

Expand Down
30 changes: 15 additions & 15 deletions scripts/prepare_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ def remove_common_guards(s):
# Remove certain macros
s = re.sub("#define TSS2_API_VERSION.*", "", s)
s = re.sub("#define TSS2_ABI_VERSION.*", "", s)
s = re.sub("#define TSS2_RC_LAYER\(level\).*", "", s)
s = re.sub("(#define.*)TSS2_RC_LAYER\(0xff\)", "\g<1>0xff0000", s)
s = re.sub(r"#define TSS2_RC_LAYER\(level\).*", "", s)
s = re.sub(r"(#define.*)TSS2_RC_LAYER\(0xff\)", r"\g<1>0xff0000", s)

# Remove comments
s = re.sub("/\*.*?\*/", "", s, flags=re.MULTILINE)
s = re.sub(r"/\*.*?\*/", "", s, flags=re.MULTILINE)

# Restructure #defines with ...
s = re.sub("(#define [A-Za-z0-9_]+) +\(\(.*?\) \(.*?\)\)", "\g<1>...", s)
s = re.sub("(#define [A-Za-z0-9_]+) +\(\(\(.*?\) .*\)", "\g<1>...", s)
s = re.sub("(#define [A-Za-z0-9_]+) +\(\(.*?\).*?\) ", "\g<1>...", s)
s = re.sub(r"(#define [A-Za-z0-9_]+) +\(\(.*?\) \(.*?\)\)", r"\g<1>...", s)
s = re.sub(r"(#define [A-Za-z0-9_]+) +\(\(\(.*?\) .*\)", r"\g<1>...", s)
s = re.sub(r"(#define [A-Za-z0-9_]+) +\(\(.*?\).*?\) ", r"\g<1>...", s)
s = re.sub(
"(#define [A-Za-z0-9_]+) .*\n.*?.*\)\)", "\g<1>...", s, flags=re.MULTILINE
"(#define [A-Za-z0-9_]+) .*\n.*?.*\\)\\)", r"\g<1>...", s, flags=re.MULTILINE
)
s = re.sub("(#define [A-Za-z0-9_]+) .*", "\g<1>...", s)
s = re.sub("(#define [A-Za-z0-9_]+) .*", r"\g<1>...", s)

# Restructure structs and untions with ...
s = re.sub("\[.+?\]", "[...]", s)
s = re.sub(r"\[.+?\]", "[...]", s)

return s

Expand Down Expand Up @@ -75,7 +75,7 @@ def prepare_types(dirpath):

# Remove false define (workaround)
s = re.sub(
"#define TPM2_MAX_TAGGED_POLICIES.*\n.*TPMS_TAGGED_POLICY\)\)",
"#define TPM2_MAX_TAGGED_POLICIES.*\n.*TPMS_TAGGED_POLICY\\)\\)",
"",
s,
flags=re.MULTILINE,
Expand Down Expand Up @@ -268,19 +268,19 @@ def prepare_mu(dirpath):
# At least tpm2-tss 3.0.3 have duplicated BYTE (un)marshal functions which break cffi
# So removing them is needed until 3.1.x has reached most distributions
n = re.findall(
"TSS2_RC\s+Tss2_MU_BYTE_Marshal\(.+?\);", s, re.DOTALL | re.MULTILINE
r"TSS2_RC\s+Tss2_MU_BYTE_Marshal\(.+?\);", s, re.DOTALL | re.MULTILINE
)
if len(n) > 1:
s = re.sub(
"TSS2_RC\s+Tss2_MU_BYTE_Marshal\(.+?\);", "", s, 1, re.DOTALL | re.MULTILINE
r"TSS2_RC\s+Tss2_MU_BYTE_Marshal\(.+?\);", "", s, 1, re.DOTALL | re.MULTILINE
)

n = re.findall(
"TSS2_RC\s+Tss2_MU_BYTE_Unmarshal\(.+?\);", s, re.DOTALL | re.MULTILINE
r"TSS2_RC\s+Tss2_MU_BYTE_Unmarshal\(.+?\);", s, re.DOTALL | re.MULTILINE
)
if len(n) > 1:
s = re.sub(
"TSS2_RC\s+Tss2_MU_BYTE_Unmarshal\(.+?\);",
r"TSS2_RC\s+Tss2_MU_BYTE_Unmarshal\(.+?\);",
"",
s,
1,
Expand Down Expand Up @@ -442,7 +442,7 @@ def prepare(

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: {0} <tss2-header-dir> <output-file>".format(sys.argv[0]))
print(f"Usage: {sys.argv[0]} <tss2-header-dir> <output-file>")
exit(1)

build_fapi = pkgconfig.installed("tss2-fapi", ">=3.0.0")
Expand Down
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@


class type_generator(build_ext):
cares = set(
(
cares = {
"TPM2_ALG_ID",
"TPM2_ST",
"TPM2_ECC_CURVE",
Expand All @@ -40,8 +39,7 @@ class type_generator(build_ext):
"TPM2_GENERATED",
"ESYS_TR",
"TSS2_POLICY_PCR_SELECTOR",
)
)
}

type_mapping = {
"TPM2_ALG_ID": "TPM2_ALG",
Expand Down Expand Up @@ -268,11 +266,11 @@ def run(self):

if not self.dry_run:
self.mkpath(os.path.dirname(p))
with open(p, "wt") as tf:
with open(p, "w") as tf:
tf.seek(0)
tf.truncate(0)
tf.write(mout)
with open(vp, "wt") as vf:
with open(vp, "w") as vf:
vf.seek(0)
vf.truncate(0)
vf.write(vout)
Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/TCTI.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Optional, Tuple, Union


class PollData(object):
class PollData:
"""Initialize a PollData object with OS specific details.

Initialize a PollData object that holds all OS specific state and metadata information
Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/TSS2_Exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, rc: Union["TSS2_RC", "TPM2_RC", int]):

rc = TSS2_RC(rc)
errmsg = ffi.string(lib.Tss2_RC_Decode(rc)).decode()
super(TSS2_Exception, self).__init__(f"{errmsg}")
super().__init__(f"{errmsg}")

self._rc = rc
self._handle = 0
Expand Down
4 changes: 2 additions & 2 deletions src/tpm2_pytss/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import warnings


class base_encdec(object):
class base_encdec:
"""Base encoder/decoder for TPM types

Args:
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def decode_tpms_pcr_selection(
def decode_tpms_tagged_property(
self, dst: TPMS_TAGGED_PROPERTY, src: Dict[str, Any]
) -> TPMS_TAGGED_PROPERTY:
pmap = dict([(v, k) for k, v in self._build_pt_map().items()])
pmap = {v: k for k, v in self._build_pt_map().items()}
ps, v = src.popitem()
dst.property = pmap[ps]
if dst.property == TPM2_PT.PERMANENT:
Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _policy_cb_exec_polaction(action, userdata):
return TPM2_RC.SUCCESS


class policy(object):
class policy:
"""Initialize policy object.

Args:
Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/tsskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set(self, value):
self._trailer = b""


class TSSPrivKey(object):
class TSSPrivKey:
"""TSSPrivKey is class to create/load keys for/from tpm2-tss-engine / tpm2-openssl.

Note:
Expand Down
4 changes: 2 additions & 2 deletions src/tpm2_pytss/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TPM2_HANDLE(int):
pass


class TPM_OBJECT(object):
class TPM_OBJECT:
""" Abstract Base class for all TPM Objects. Not suitable for direct instantiation."""

def __init__(self, _cdata=None, **kwargs):
Expand Down Expand Up @@ -336,7 +336,7 @@ def __eq__(self, value):
return b == value


class TPML_Iterator(object):
class TPML_Iterator:
""" Iterator class for iterating over TPML data types.

This class is used in enumerated for loops, such as:
Expand Down
14 changes: 7 additions & 7 deletions test/TSS2_BaseTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tpm2_pytss import *


class BaseTpmSimulator(object):
class BaseTpmSimulator:
def __init__(self):
self.tpm = None
self._port = None
Expand All @@ -26,7 +26,7 @@ def ready(port):

def start(self):
logger = logging.getLogger("DEBUG")
logger.debug('Setting up simulator: "{}"'.format(self.exe))
logger.debug(f'Setting up simulator: "{self.exe}"')

tpm = None
for _ in range(0, 20):
Expand Down Expand Up @@ -89,13 +89,13 @@ def _start(self, port):
"socket",
"--tpm2",
"--server",
"port={}".format(port),
f"port={port}",
"--ctrl",
"type=tcp,port={}".format(port + 1),
f"type=tcp,port={port + 1}",
"--flags",
"not-need-init",
"--tpmstate",
"dir={}".format(self.working_dir.name),
f"dir={self.working_dir.name}",
]

tpm = subprocess.Popen(cmd)
Expand Down Expand Up @@ -129,7 +129,7 @@ def _start(self, port):
cwd = os.getcwd()
os.chdir(self.working_dir.name)
try:
cmd = ["tpm_server", "-rm", "-port", "{}".format(port)]
cmd = ["tpm_server", "-rm", "-port", f"{port}"]
tpm = subprocess.Popen(cmd)
return tpm

Expand All @@ -150,7 +150,7 @@ def get_tcti(self):
return TCTILdr("mssim", f"port={self._port}")


class TpmSimulator(object):
class TpmSimulator:

SIMULATORS = [
SwtpmSimulator,
Expand Down
6 changes: 3 additions & 3 deletions test/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def test_verify_signature_bad(self):

hsig = TPMT_SIGNATURE(sigAlg=TPM2_ALG.HMAC)
with self.assertRaises(ValueError) as e:
crypto._verify_signature(hsig, str("not bytes"), b"1234")
crypto._verify_signature(hsig, "not bytes", b"1234")
self.assertEqual(
str(e.exception),
f"bad key type for {TPM2_ALG.HMAC}, expected bytes, got str",
Expand All @@ -888,7 +888,7 @@ def test_verify_signature_bad(self):

badecc = TPMT_SIGNATURE(sigAlg=TPM2_ALG.ECDSA)
with self.assertRaises(ValueError) as e:
crypto._verify_signature(badecc, str("bad"), b"1234")
crypto._verify_signature(badecc, "bad", b"1234")
self.assertEqual(
str(e.exception),
f"bad key type for {TPM2_ALG.ECDSA}, expected ECC public key, got str",
Expand All @@ -904,7 +904,7 @@ def test_verify_signature_bad(self):

badrsa = TPMT_SIGNATURE(sigAlg=TPM2_ALG.RSAPSS)
with self.assertRaises(ValueError) as e:
crypto._verify_signature(badrsa, str("bad"), b"1234")
crypto._verify_signature(badrsa, "bad", b"1234")
self.assertEqual(
str(e.exception),
f"bad key type for {TPM2_ALG.RSAPSS}, expected RSA public key, got str",
Expand Down
2 changes: 1 addition & 1 deletion test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ def test_TPMS_SENSITIVE_CREATE_with_string(self):

x = TPMS_SENSITIVE_CREATE(userAuth="password")
p = str(x.userAuth)
self.assertEqual(p, binascii.hexlify("password".encode()).decode())
self.assertEqual(p, binascii.hexlify(b"password").decode())

def test_TPM2B_SIMPLE_OBJECT(self):
bob = b"bunchofbytes"
Expand Down
Loading