Use at least two bytes for filesize in FCP template (#116)

* Fix length of filesize parameter in FCP template

'Number of data bytes in the file' parameters should be represented on
two bytes in FCP.

* Extendable length of filesize parameter in FCP

Increase length of filesize parameter in FCP template if can't be
represented on two bytes.
This commit is contained in:
Dániel SÜTTŐ
2018-01-10 23:07:08 +01:00
committed by Frank Morgner
parent b0783bd373
commit a9482d9f99
2 changed files with 5 additions and 5 deletions

View File

@@ -626,7 +626,7 @@ class MF(DF):
fdm.append("%c\x00" % TAG["SHORTFID"])
if isinstance(file, TransparentStructureEF):
l = inttostring(len(file.data))
l = inttostring(len(file.data), 2, True)
fdm.append("%c%c%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
chr(len(l)), l))
fdm.append("%c%c%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
@@ -643,9 +643,9 @@ class MF(DF):
else:
l += len(r.data)
fdm.append("%c\x02%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
inttostring(l, 2)))
inttostring(l, 2, True)))
fdm.append("%c\x02%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
inttostring(l, 2)))
inttostring(l, 2, True)))
l = len(records)
fdm.append("%c\x06%c%c%c%c%s" % (TAG["FILEDISCRIPTORBYTE"],
file.filedescriptor, file.datacoding,

View File

@@ -27,7 +27,7 @@ def stringtoint(str):
return 0
def inttostring(i, length=None):
def inttostring(i, length=None, len_extendable=False):
str = "%x" % i
if len(str) % 2 == 0:
str = str.decode('hex')
@@ -36,7 +36,7 @@ def inttostring(i, length=None):
if length:
l = len(str)
if l > length:
if l > length and not len_extendable:
raise ValueError("i too big for the specified stringlength")
else:
str = chr(0)*(length-l) + str