mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-17 02:48:34 +03:00
Add codecs for EF_SPN and GSM strings via construct
This will replace the hand-crafted codec for EF_SPN by a struct definition using the construct library. Old encoders are updated and kept for API compatibility but are not used internally anymore. New data structures: * Rpad(Adapter): Right-padded bytestring (0xff, adjustable) * GsmStringAdapter(Adapter): Codec for "SMS default 7-bit coded alphabet as defined int TS 23.038" using the gsm0338 library. * GsmString(n): Convenient wrapper of both above Adjustments: * utils: update+deprecate old dec_spn(), enc_spn() * remove refs to deprecated functions Change-Id: Ia1d3a3835933bac0002b7c52511481dd8094b994
This commit is contained in:
@@ -248,17 +248,23 @@ def dec_plmn(threehexbytes:Hexstr) -> dict:
|
||||
return res
|
||||
|
||||
def dec_spn(ef):
|
||||
byte1 = int(ef[0:2])
|
||||
hplmn_disp = (byte1&0x01 == 0x01)
|
||||
oplmn_disp = (byte1&0x02 == 0x02)
|
||||
name = h2s(ef[2:])
|
||||
return (name, hplmn_disp, oplmn_disp)
|
||||
"""Obsolete, kept for API compatibility"""
|
||||
from ts_51_011 import EF_SPN
|
||||
abstract_data = EF_SPN().decode_hex(ef)
|
||||
show_in_hplmn = abstract_data['show_in_hplmn']
|
||||
hide_in_oplmn = abstract_data['hide_in_oplmn']
|
||||
name = abstract_data['spn']
|
||||
return (name, show_in_hplmn, hide_in_oplmn)
|
||||
|
||||
def enc_spn(name:str, hplmn_disp=False, oplmn_disp=False):
|
||||
byte1 = 0x00
|
||||
if hplmn_disp: byte1 = byte1|0x01
|
||||
if oplmn_disp: byte1 = byte1|0x02
|
||||
return i2h([byte1])+s2h(name)
|
||||
def enc_spn(name:str, show_in_hplmn=False, hide_in_oplmn=False):
|
||||
"""Obsolete, kept for API compatibility"""
|
||||
from ts_51_011 import EF_SPN
|
||||
abstract_data = {
|
||||
'hide_in_oplmn' : hide_in_oplmn,
|
||||
'show_in_hplmn' : show_in_hplmn,
|
||||
'spn' : name,
|
||||
}
|
||||
return EF_SPN().encode_hex(abstract_data)
|
||||
|
||||
def hexstr_to_Nbytearr(s, nbytes):
|
||||
return [s[i:i+(nbytes*2)] for i in range(0, len(s), (nbytes*2)) ]
|
||||
|
||||
Reference in New Issue
Block a user