mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
utils.py: de-couple sanitize_pin_adm from argparse 'opts'
This allows the function to be re-used in other contexts Change-Id: I116e85acca3aeb0a0c24f74653c500ac2dc1d844
This commit is contained in:
@@ -446,7 +446,7 @@ def gen_parameters(opts):
|
||||
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:
|
||||
|
||||
@@ -571,7 +571,7 @@ def enc_addr_tlv(addr, addr_type='00'):
|
||||
|
||||
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 @@ def sanitize_pin_adm(opts):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user