[S] Change in pysim[master]: pySim-shell: Improved argument validation for verify_adm argument

2023-11-03 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/34945?usp=email )

Change subject: pySim-shell: Improved argument validation for verify_adm 
argument
..

pySim-shell: Improved argument validation for verify_adm argument

Let's make sure we don't even bother to ask the card to verify
anything as ADM1 pin which is not either a sequence of decimal digits
or an even number of hex digits (even number of bytes).

Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 26 insertions(+), 1 deletion(-)

Approvals:
  pespin: Looks good to me, but someone else must approve
  fixeria: Looks good to me, approved
  Jenkins Builder: Verified




diff --git a/pySim-shell.py b/pySim-shell.py
index 7aaa234..c2bb15c 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -53,6 +53,7 @@
 from pySim.cards import card_detect, SimCardBase, UiccCardBase
 from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, 
bertlv_parse_one, sw_match
 from pySim.utils import sanitize_pin_adm, tabulate_str_list, 
boxed_heading_str, Hexstr, dec_iccid
+from pySim.utils import is_hexstr_or_decimal
 from pySim.card_handler import CardHandler, CardHandlerAuto

 from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication
@@ -777,7 +778,7 @@
 self._cmd.poutput("no description available")

 verify_adm_parser = argparse.ArgumentParser()
-verify_adm_parser.add_argument('ADM1', nargs='?', type=str,
+verify_adm_parser.add_argument('ADM1', nargs='?', 
type=is_hexstr_or_decimal,
help='ADM1 pin value. If none given, CSV 
file will be queried')

 @cmd2.with_argparser(verify_adm_parser)
diff --git a/pySim/utils.py b/pySim/utils.py
index 7459a3f..92bf70f 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1467,3 +1467,14 @@
 def all_subclasses(cls) -> set:
 """Recursively get all subclasses of a specified class"""
 return set(cls.__subclasses__()).union([s for c in cls.__subclasses__() 
for s in all_subclasses(c)])
+
+def is_hexstr_or_decimal(instr: str) -> str:
+"""Method that can be used as 'type' in argparse.add_argument() to 
validate the value consists of
+[hexa]decimal digits only."""
+if instr.isdecimal():
+return instr
+if not all(c in string.hexdigits for c in instr):
+raise ValueError('Input must be [hexa]decimal')
+if len(instr) & 1:
+raise ValueError('Input has un-even number of hex digits')
+return instr

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 3
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-MessageType: merged


[S] Change in pysim[master]: pySim-shell: Improved argument validation for verify_adm argument

2023-11-02 Thread fixeria
Attention is currently required from: laforge.

fixeria has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/34945?usp=email )

Change subject: pySim-shell: Improved argument validation for verify_adm 
argument
..


Patch Set 3: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 3
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Fri, 03 Nov 2023 05:59:24 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[S] Change in pysim[master]: pySim-shell: Improved argument validation for verify_adm argument

2023-11-02 Thread pespin
Attention is currently required from: laforge.

pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/34945?usp=email )

Change subject: pySim-shell: Improved argument validation for verify_adm 
argument
..


Patch Set 2: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Thu, 02 Nov 2023 09:34:01 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[S] Change in pysim[master]: pySim-shell: Improved argument validation for verify_adm argument

2023-11-01 Thread laforge
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/pysim/+/34945?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder


Change subject: pySim-shell: Improved argument validation for verify_adm 
argument
..

pySim-shell: Improved argument validation for verify_adm argument

Let's make sure we don't even bother to ask the card to verify
anything as ADM1 pin which is not either a sequence of decimal digits
or an even number of hex digits (even number of bytes).

Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 26 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/34945/2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: newpatchset


[S] Change in pysim[master]: pySim-shell: Improved argument validation for verify_adm argument

2023-11-01 Thread laforge
laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/34945?usp=email )


Change subject: pySim-shell: Improved argument validation for verify_adm 
argument
..

pySim-shell: Improved argument validation for verify_adm argument

Let's make sure we don't even bother to ask the card to verify
anything as ADM1 pin which is not either a sequence of decimal digits
or an even number of hex digits (even number of bytes).

Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 26 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/34945/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 7aaa234..c59d18b 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -53,6 +53,7 @@
 from pySim.cards import card_detect, SimCardBase, UiccCardBase
 from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, 
bertlv_parse_one, sw_match
 from pySim.utils import sanitize_pin_adm, tabulate_str_list, 
boxed_heading_str, Hexstr, dec_iccid
+from pySim.utils import hexstr_or_decimal
 from pySim.card_handler import CardHandler, CardHandlerAuto

 from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication
@@ -777,7 +778,7 @@
 self._cmd.poutput("no description available")

 verify_adm_parser = argparse.ArgumentParser()
-verify_adm_parser.add_argument('ADM1', nargs='?', type=str,
+verify_adm_parser.add_argument('ADM1', nargs='?', type=hexstr_or_decimal,
help='ADM1 pin value. If none given, CSV 
file will be queried')

 @cmd2.with_argparser(verify_adm_parser)
diff --git a/pySim/utils.py b/pySim/utils.py
index 7459a3f..e6a6d2d 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1467,3 +1467,14 @@
 def all_subclasses(cls) -> set:
 """Recursively get all subclasses of a specified class"""
 return set(cls.__subclasses__()).union([s for c in cls.__subclasses__() 
for s in all_subclasses(c)])
+
+def hexstr_or_decimal(instr: str):
+"""Method that can be used as 'type' in argparse.add_argument() to 
validate the value consists of
+[hexa]decimal digits only."""
+if instr.isdecimal():
+return instr
+if not all(c in string.hexdigits for c in instr):
+raise ValueError('Input must be [hexa]decimal')
+if len(instr) & 1:
+raise ValueError('Input has un-even number of hex digits')
+return instr

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 1
Gerrit-Owner: laforge 
Gerrit-MessageType: newchange