mirror of
https://sharelatex.tu-darmstadt.de/git/681e0e7a3a9c7c9c6b8bb298
synced 2025-12-08 05:27:59 +00:00
Update on Overleaf.
This commit is contained in:
@@ -633,95 +633,10 @@ While the implemented library provides a programmatic interface to the \gls{lpa}
|
||||
|
||||
The \gls{cli} is built using Python’s standard \texttt{argparse} module for argument parsing, extended with \texttt{argcomplete} to enable shell auto-completion. For improved readability and formatting of terminal output, the \texttt{rich} library is used. This combination allows for an interactive, user-friendly \gls{cli} with both developer ergonomics and production readiness in mind.
|
||||
|
||||
\subsection*{Structure}
|
||||
\todo{Put this section into the appendix}
|
||||
The CLI is organized around three core commands:
|
||||
\begin{itemize}
|
||||
\item \textbf{tracing} — Interfaces with the \texttt{simtrace2} device and the \gls{lpa} to capture \gls{apdu} traffic in real time. This functionality is discussed in detail in \cref{sec:tracing}.
|
||||
\item \textbf{lpa} — Exposes \gls{euicc} communication features such as profile management, notification handling, and remote procedure execution via the \gls{cli}.
|
||||
\item \textbf{fuzzing} — Wraps both \gls{apdu}-level and data-level fuzzing. Additionally, it provides a \texttt{compare} command to compare multiple trace recordings and highlight structural differences in JSON format.
|
||||
\end{itemize}
|
||||
|
||||
Each of these commands is implemented in its respective subfolder (e.g., \texttt{tracing/}, \texttt{lpa/}, \texttt{fuzz/}). The modular structure of the \gls{cli} is shown in \cref{fig:cli_structure}, which illustrates how the subcommands map to the file and folder hierarchy of the project.
|
||||
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\begin{forest}
|
||||
for tree={
|
||||
font=\ttfamily,
|
||||
grow'=0,
|
||||
child anchor=west,
|
||||
parent anchor=south,
|
||||
anchor=west,
|
||||
calign=first,
|
||||
inner sep=1pt,
|
||||
l=1.5em,
|
||||
s sep=3pt,
|
||||
edge path={
|
||||
\noexpand\path [draw, \forestoption{edge}]
|
||||
(!u.south west) +(3.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
|
||||
},
|
||||
before typesetting nodes={
|
||||
if n=1
|
||||
{insert before={[,phantom]}}
|
||||
{}
|
||||
},
|
||||
fit=band,
|
||||
before computing xy={l=15pt},
|
||||
}
|
||||
[cli
|
||||
[\_\_init\_\_.py]
|
||||
[fuzzer
|
||||
[\_\_init\_\_.py]
|
||||
[apdu\_fuzzer.py]
|
||||
[compare.py]
|
||||
[data\_fuzzer.py]
|
||||
]
|
||||
[trace
|
||||
[\_\_init\_\_.py]
|
||||
[record.py]
|
||||
[replay.py]
|
||||
]
|
||||
[lpa
|
||||
[\_\_init\_\_.py]
|
||||
[euicc.py]
|
||||
[notification.py]
|
||||
[profile.py]
|
||||
]
|
||||
]
|
||||
\end{forest}
|
||||
\caption{\gls{cli} folder structure and modular separation of functionality}
|
||||
\label{fig:cli_structure}
|
||||
\end{figure}
|
||||
|
||||
\paragraph{Dispatch and Argument Parsing}
|
||||
Each submodule implements a \texttt{run()} function that parses the subcommand’s specific arguments and dispatches execution to the appropriate internal handler. At the top level, the root \texttt{\_\_init\_\_.py} file defines the global parser, registers the subcommands via subparsers, and handles any global options. This design pattern is shown in \cref{lst:cli_parser}.
|
||||
|
||||
|
||||
\begin{lstlisting}[caption={Top-level CLI dispatch pattern}, label={lst:cli_parser}]
|
||||
def add_subparser(parent_parser: argparse._SubParsersAction) -> None:
|
||||
trace_parser: argparse.ArgumentParser = parent_parser.add_parser(
|
||||
"trace",
|
||||
help="Trace-level operations (record, replay)",
|
||||
formatter_class=RichHelpFormatter,
|
||||
)
|
||||
trace_subparsers = trace_parser.add_subparsers(dest="trace_command", required=True)
|
||||
record.add_subparser(trace_subparsers)
|
||||
replay.add_subparser(trace_subparsers)
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> None:
|
||||
if args.trace_command == "record":
|
||||
record.run(args)
|
||||
elif args.trace_command == "replay":
|
||||
replay.run(args)
|
||||
\end{lstlisting}
|
||||
|
||||
|
||||
Each subcommand module (e.g., \texttt{fuzz/data\_fuzz.py}) provides its own parser configuration and encapsulated logic, adhering to a clearly defined interface.
|
||||
The CLI structure is further detailed in \cref{sec:cli_structure}.
|
||||
|
||||
\paragraph{Integration with Pytest}
|
||||
The data fuzzing component internally wraps \texttt{pytest}, leveraging the structure of Python test classes defined with the Hypothesis framework (cf. Section~\ref{subsec:data_fuzzing}). Each test class corresponds to a group of \gls{rsp} commands. By invoking the data fuzzing \gls{cli}, all available test classes are executed against the connected \gls{euicc}, with proper initialization and teardown logic handled automatically.
|
||||
|
||||
\subsection*{Extensibility}
|
||||
\paragraph{Extensibility}
|
||||
The \gls{cli} is designed with extensibility as a primary concern. Adding new commands requires minimal effort: developers only need to create a new subfolder, define a \texttt{run()} function, and register the new command in the main \gls{cli} dispatcher. Moreover, the \gls{cli} is completely decoupled from the core library logic, ensuring that library users are not forced to depend on the \gls{cli} subsystem and vice versa.
|
||||
|
||||
Reference in New Issue
Block a user