filesystem: add attribute "leftpad" to class LinFixedEF

In some cases, the specs do not specify an absolute record length.
Instead there may be only a minimum record length specified. The card
vendor may then chose to use larger record length at will. This usually
is no problem since the data is usually written from the left and the
remaining bytes are padded at the end (right side) of the data. However
in some rare cases (EF.MSISDN, see also 3GPP TS 51.011, section 10.5.5)
the data must be written right-aligned towards the physical record
length. This means that the data is padded from the left in this case.

To fix this: Let's add a "leftpad" flag to LinFixedEF, which we set to
true in those corner cases. The code that updates the record in
commands.py must then check this flag and padd the data accordingly.

Change-Id: I241d9fd656f9064a3ebb4e8e01a52b6b030f9923
Related: OS#5714
diff --git a/pySim/commands.py b/pySim/commands.py
index 477cb2b..e072069 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -26,7 +26,7 @@
 
 from construct import *
 from pySim.construct import LV
-from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
+from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
 from pySim.utils import Hexstr, SwHexstr, ResTuple
 from pySim.exceptions import SwMatchError
 from pySim.transport import LinkBase
@@ -269,7 +269,7 @@
                 data.lower(), res[0].lower()))
 
     def update_record(self, ef: Path, rec_no: int, data: Hexstr, force_len: bool = False,
-                      verify: bool = False, conserve: bool = False) -> ResTuple:
+                      verify: bool = False, conserve: bool = False, leftpad: bool = False) -> ResTuple:
         """Execute UPDATE RECORD.
 
         Args:
@@ -279,6 +279,7 @@
                 force_len : enforce record length by using the actual data length
                 verify : verify data by re-reading the record
                 conserve : read record and compare it with data, skip write on match
+                leftpad : apply 0xff padding from the left instead from the right side.
         """
 
         res = self.select_path(ef)
@@ -295,7 +296,10 @@
                 raise ValueError('Data length exceeds record length (expected max %d, got %d)' % (
                     rec_length, len(data) // 2))
             elif (len(data) // 2 < rec_length):
-                data = rpad(data, rec_length * 2)
+                if leftpad:
+                    data = lpad(data, rec_length * 2)
+                else:
+                    data = rpad(data, rec_length * 2)
 
         # Save write cycles by reading+comparing before write
         if conserve: