mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-11-06 05:25:14 +03:00
pySim-shell: Validate that argument to 'apdu' command is proper hexstr
Let's not even send anything to the card if it's not an even number of hexadecimal digits Change-Id: I58465244101cc1a976e5a17af2aceea1cf9f9b54
This commit is contained in:
1 parent
f9ea63ea51
commit
4e59d89a5d
2 files changed
+11
-2
No files matched your search
@@ -1478,3 +1478,12 @@ def is_hexstr_or_decimal(instr: str) -> str:
|
||||
if len(instr) & 1:
|
||||
raise ValueError('Input has un-even number of hex digits')
|
||||
return instr
|
||||
|
||||
def is_hexstr(instr: str) -> str:
|
||||
"""Method that can be used as 'type' in argparse.add_argument() to validate the value consists of
|
||||
an even sequence of hexadecimal digits only."""
|
||||
if not all(c in string.hexdigits for c in instr):
|
||||
raise ValueError('Input must be hexadecimal')
|
||||
if len(instr) & 1:
|
||||
raise ValueError('Input has un-even number of hex digits')
|
||||
return instr
|
||||
Reference in new issue
Block a user