Jean-Pierre Marcotte has uploaded this change for review. (
https://gerrit.osmocom.org/c/python/pyosmocom/+/38687?usp=email )
Change subject: Fixing 3-digit MNC PlmnAdapter encoding and decoding. Adding
test_plmn_adapter.
......................................................................
Fixing 3-digit MNC PlmnAdapter encoding and decoding.
Adding test_plmn_adapter.
Change-Id: I3811b227d629bd4e051a480c9622967e31f8a376
---
M src/osmocom/construct.py
M tests/test_construct.py
2 files changed, 18 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/87/38687/1
diff --git a/src/osmocom/construct.py b/src/osmocom/construct.py
index 5a78246..d96ab5e 100644
--- a/src/osmocom/construct.py
+++ b/src/osmocom/construct.py
@@ -268,14 +268,14 @@
if bcd[3] == 'f':
return '-'.join([bcd[:3], bcd[4:]])
else:
- return '-'.join([bcd[:3], bcd[3:]])
+ return '-'.join([bcd[:3], bcd[4:6]+bcd[3]])
def _encode(self, obj, context, path):
l = obj.split('-')
if len(l[1]) == 2:
bcd = l[0] + 'f' + l[1]
else:
- bcd = l[0] + l[1]
+ bcd = l[0] + l[1][2] + l[1][0:2]
return super()._encode(bcd, context, path)
class InvertAdapter(Adapter):
diff --git a/tests/test_construct.py b/tests/test_construct.py
index ba4f8f4..b069809 100755
--- a/tests/test_construct.py
+++ b/tests/test_construct.py
@@ -112,6 +112,22 @@
with self.subTest(type='encode', name=exp_dec):
re_enc = ad._encode(exp_dec, None, None)
self.assertEqual(re_enc, enc)
+
+ def test_plmn_adapter(self):
+ ad = PlmnAdapter(Bytes(3))
+ td = [
+ (bytes.fromhex('62f210'),'262-01'),
+ (bytes.fromhex('21f354'),"123-45"),
+ (bytes.fromhex('216354'),"123-456"),
+ (bytes.fromhex('030251'),"302-150")
+ ]
+ for enc, exp_dec in td:
+ with self.subTest(type='decode', name=exp_dec):
+ dec = ad._decode(enc, None, None)
+ self.assertEqual(dec, exp_dec)
+ with self.subTest(type='encode', name=exp_dec):
+ re_enc = ad._encode(exp_dec, None, None)
+ self.assertEqual(re_enc, enc)
class TestAsn1DerInteger(unittest.TestCase):
--
To view, visit
https://gerrit.osmocom.org/c/python/pyosmocom/+/38687?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: I3811b227d629bd4e051a480c9622967e31f8a376
Gerrit-Change-Number: 38687
Gerrit-PatchSet: 1
Gerrit-Owner: Jean-Pierre Marcotte <jean-pierre.marcotte.1(a)ens.etsmtl.ca>