Skip to content

Commit

Permalink
ex: use .pcap files from new file location
Browse files Browse the repository at this point in the history
  • Loading branch information
joholl committed Mar 23, 2023
1 parent e825054 commit c12d35c
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/tpmstream/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import binascii
import glob
import os
import sys
from argparse import ArgumentParser, FileType
from difflib import get_close_matches
Expand All @@ -9,6 +7,7 @@
from tpmstream.spec.structures.constants import TPM_CC

from . import __version__
from .data import example_data_files
from .io import bytes_from_files
from .io.auto import Auto
from .io.binary import Binary
Expand Down Expand Up @@ -65,13 +64,6 @@ def convert(args):


def examples(args):
# TODO we can do better
TPMSTREAM_PATH = os.path.abspath(os.path.dirname(__file__))
PCAP_DIRECORY_PATH = os.path.join(
os.path.dirname(os.path.dirname(TPMSTREAM_PATH)), "test/pcap/*.pcap"
)
paths = sorted(glob.glob(PCAP_DIRECORY_PATH))

if args.command is None:
for command_code in TPM_CC:
# remove leading "TPM_CC_"
Expand All @@ -97,8 +89,8 @@ def examples(args):
except AttributeError as e:
raise AttributeError(f"Unknown commandCode: {args.command}") from e

for path in paths:
with open(path, "rb") as file:
for example_data_file in example_data_files:
with open(example_data_file, "rb") as file:
events = list(Auto.marshal(tpm_type=Command, buffer=bytes_from_files(file)))

# TODO Get Responses, too. Response objects should know they commandCode, maybe via ._commandCode?
Expand Down

0 comments on commit c12d35c

Please sign in to comment.