laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/35243?usp=email )

Change subject: tlv: Fix encoding of zero-valued TLVs
......................................................................

tlv: Fix encoding of zero-valued TLVs

If a TLV was elementary (no nested IEs), and it had only a single
integer content whose value is 0, we erroneously encoded that as
zero-length TLV (len=0, no value part):

>>> rf = pySim.euicc.RefreshFlag(decoded=0);
>>> rf.to_bytes()
b''
>>> rf.to_tlv()
b'\x81\x00'

After this change it is correct:

>>> rf = pySim.euicc.RefreshFlag(decoded=0);
>>> rf.to_bytes()
b'\x00'
>>> rf.to_tlv()
b'\x81\x01\x00'

Change-Id: I5f4c0555cff7df9ccfc4a56da12766d1bf89122f
---
M pySim/tlv.py
1 file changed, 28 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved




diff --git a/pySim/tlv.py b/pySim/tlv.py
index 1ecc806..c85d92b 100644
--- a/pySim/tlv.py
+++ b/pySim/tlv.py
@@ -87,7 +87,7 @@
     def to_bytes(self) -> bytes:
         """Convert from internal representation to binary bytes.  Store the 
binary result
         in the internal state and return it."""
-        if not self.decoded:
+        if self.decoded == None:
             do = b''
         elif self._construct:
             do = self._construct.build(self.decoded, total_len=None)

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35243?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5f4c0555cff7df9ccfc4a56da12766d1bf89122f
Gerrit-Change-Number: 35243
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to