This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
dexter gerrit-no-reply at lists.osmocom.orgdexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/18207 )
Change subject: pysim-prog: move ADM sanitation to utils.py
......................................................................
pysim-prog: move ADM sanitation to utils.py
The lower part of gen_parameters() in pySim-prog.py contains some code
that checks whether the ADM pin supplied in its hexadecimal or in its
string form and generates a sanitised pin_adm from that. Lets separate
this part as it may become useful elsewhere too.
Change-Id: Ifead29724cc13a91de9e2e89314d7fb23c063d50
---
M pySim-prog.py
M pySim/utils.py
2 files changed, 31 insertions(+), 21 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/07/18207/1
diff --git a/pySim-prog.py b/pySim-prog.py
index e3045a6..8bc474a 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -405,27 +405,7 @@
else:
opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
-
- 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])
- 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
- # Ensure that it's hex-encoded
- try:
- try_encode = h2b(pin_adm)
- except ValueError:
- raise ValueError("PIN-ADM needs to be hex encoded using this option")
- else:
- raise ValueError("PIN-ADM needs to be exactly 16 digits (hex encoded)")
+ pin_adm = sanitize_pin_adm(opts)
# Return that
return {
diff --git a/pySim/utils.py b/pySim/utils.py
index 1980685..aab5d02 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -359,3 +359,33 @@
avail_st += '\tService %d - %s\n' % ((8*i) + j, lookup_map[(8*i) + j])
byte = byte >> 1
return avail_st
+
+
+def sanitize_pin_adm(opts):
+ """The ADM pin can be supplied either in its hexadecimal form or as
+ ascii string. This function checks the supplied opts parameter and
+ returns the pin_adm as hex encoded string, regardles in which form
+ 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])
+ 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
+ # Ensure that it's hex-encoded
+ try:
+ try_encode = h2b(pin_adm)
+ except ValueError:
+ raise ValueError("PIN-ADM needs to be hex encoded using this option")
+ else:
+ raise ValueError("PIN-ADM needs to be exactly 16 digits (hex encoded)")
+
+ return pin_adm
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/18207
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ifead29724cc13a91de9e2e89314d7fb23c063d50
Gerrit-Change-Number: 18207
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200511/2810815b/attachment.htm>