Change in pysim[master]: utils.py: de-couple sanitize_pin_adm from argparse 'opts'

laforge gerrit-no-reply at lists.osmocom.org
Tue Mar 2 06:36:03 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23169 )


Change subject: utils.py: de-couple sanitize_pin_adm from argparse 'opts'
......................................................................

utils.py: de-couple sanitize_pin_adm from argparse 'opts'

This allows the function to be re-used in other contexts

Change-Id: I116e85acca3aeb0a0c24f74653c500ac2dc1d844
---
M pySim-prog.py
M pySim/utils.py
2 files changed, 8 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/69/23169/1

diff --git a/pySim-prog.py b/pySim-prog.py
index fbf2b73..4f54963 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -446,7 +446,7 @@
 	else:
 		opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
 
-	pin_adm = sanitize_pin_adm(opts)
+	pin_adm = sanitize_pin_adm(opts.pin_adm, opts.pin_adm_hex)
 
 	# ePDG Selection Information
 	if opts.epdgSelection:
diff --git a/pySim/utils.py b/pySim/utils.py
index 1373551..a733d87 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -571,7 +571,7 @@
 
 	return s
 
-def sanitize_pin_adm(opts):
+def sanitize_pin_adm(pin_adm, pin_adm_hex = None):
 	"""
 	The ADM pin can be supplied either in its hexadecimal form or as
 	ascii string. This function checks the supplied opts parameter and
@@ -579,19 +579,17 @@
 	it was originally supplied by the user
 	"""
 
-	pin_adm = None
-
-	if opts.pin_adm is not None:
-		if len(opts.pin_adm) <= 8:
-			pin_adm = ''.join(['%02x'%(ord(x)) for x in opts.pin_adm])
+	if pin_adm is not None:
+		if len(pin_adm) <= 8:
+			pin_adm = ''.join(['%02x'%(ord(x)) for x in pin_adm])
 			pin_adm = rpad(pin_adm, 16)
 
 		else:
 			raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
 
-	if opts.pin_adm_hex is not None:
-		if len(opts.pin_adm_hex) == 16:
-			pin_adm = opts.pin_adm_hex
+	if pin_adm_hex is not None:
+		if len(pin_adm_hex) == 16:
+			pin_adm = pin_adm_hex
 			# Ensure that it's hex-encoded
 			try:
 				try_encode = h2b(pin_adm)

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23169
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I116e85acca3aeb0a0c24f74653c500ac2dc1d844
Gerrit-Change-Number: 23169
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210302/f72fde7f/attachment.htm>


More information about the gerrit-log mailing list