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:
|
else:
|
||||||
opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
|
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
|
# ePDG Selection Information
|
||||||
if opts.epdgSelection:
|
if opts.epdgSelection:
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ def enc_addr_tlv(addr, addr_type='00'):
|
|||||||
|
|
||||||
return s
|
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
|
The ADM pin can be supplied either in its hexadecimal form or as
|
||||||
ascii string. This function checks the supplied opts parameter and
|
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
|
it was originally supplied by the user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pin_adm = None
|
if pin_adm is not None:
|
||||||
|
if len(pin_adm) <= 8:
|
||||||
if opts.pin_adm is not None:
|
pin_adm = ''.join(['%02x'%(ord(x)) for x in pin_adm])
|
||||||
if len(opts.pin_adm) <= 8:
|
|
||||||
pin_adm = ''.join(['%02x'%(ord(x)) for x in opts.pin_adm])
|
|
||||||
pin_adm = rpad(pin_adm, 16)
|
pin_adm = rpad(pin_adm, 16)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
|
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
|
||||||
|
|
||||||
if opts.pin_adm_hex is not None:
|
if pin_adm_hex is not None:
|
||||||
if len(opts.pin_adm_hex) == 16:
|
if len(pin_adm_hex) == 16:
|
||||||
pin_adm = opts.pin_adm_hex
|
pin_adm = pin_adm_hex
|
||||||
# Ensure that it's hex-encoded
|
# Ensure that it's hex-encoded
|
||||||
try:
|
try:
|
||||||
try_encode = h2b(pin_adm)
|
try_encode = h2b(pin_adm)
|
||||||
|
|||||||
Reference in New Issue
Block a user