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:
committed by
Frank Morgner
parent
b0783bd373
commit
a9482d9f99
@@ -626,7 +626,7 @@ class MF(DF):
|
|||||||
fdm.append("%c\x00" % TAG["SHORTFID"])
|
fdm.append("%c\x00" % TAG["SHORTFID"])
|
||||||
|
|
||||||
if isinstance(file, TransparentStructureEF):
|
if isinstance(file, TransparentStructureEF):
|
||||||
l = inttostring(len(file.data))
|
l = inttostring(len(file.data), 2, True)
|
||||||
fdm.append("%c%c%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
fdm.append("%c%c%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
||||||
chr(len(l)), l))
|
chr(len(l)), l))
|
||||||
fdm.append("%c%c%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
fdm.append("%c%c%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
||||||
@@ -643,9 +643,9 @@ class MF(DF):
|
|||||||
else:
|
else:
|
||||||
l += len(r.data)
|
l += len(r.data)
|
||||||
fdm.append("%c\x02%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
fdm.append("%c\x02%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
||||||
inttostring(l, 2)))
|
inttostring(l, 2, True)))
|
||||||
fdm.append("%c\x02%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
fdm.append("%c\x02%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
||||||
inttostring(l, 2)))
|
inttostring(l, 2, True)))
|
||||||
l = len(records)
|
l = len(records)
|
||||||
fdm.append("%c\x06%c%c%c%c%s" % (TAG["FILEDISCRIPTORBYTE"],
|
fdm.append("%c\x06%c%c%c%c%s" % (TAG["FILEDISCRIPTORBYTE"],
|
||||||
file.filedescriptor, file.datacoding,
|
file.filedescriptor, file.datacoding,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def stringtoint(str):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def inttostring(i, length=None):
|
def inttostring(i, length=None, len_extendable=False):
|
||||||
str = "%x" % i
|
str = "%x" % i
|
||||||
if len(str) % 2 == 0:
|
if len(str) % 2 == 0:
|
||||||
str = str.decode('hex')
|
str = str.decode('hex')
|
||||||
@@ -36,7 +36,7 @@ def inttostring(i, length=None):
|
|||||||
|
|
||||||
if length:
|
if length:
|
||||||
l = len(str)
|
l = len(str)
|
||||||
if l > length:
|
if l > length and not len_extendable:
|
||||||
raise ValueError("i too big for the specified stringlength")
|
raise ValueError("i too big for the specified stringlength")
|
||||||
else:
|
else:
|
||||||
str = chr(0)*(length-l) + str
|
str = chr(0)*(length-l) + str
|
||||||
|
|||||||
Reference in New Issue
Block a user