<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/24008">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">commands: pad short data input in update_record()<br><br>The method update_record as a "force_len" parameter, which is somewhat<br>irretatating. Some explainatory comments and a reformat of the if<br>statement will help to make it more understandable to the api user.<br><br>In the non force_len case the method determines the record length from<br>the select response and throws an exception if the data input does not<br>match that length. This makes sense if the data input exceeds the<br>record length of the file but if the data input is less then the record<br>length the situation is fixable by padding the input with 0xff. This<br>also a quite common case because in some situation it is not guaranteed<br>that the data will fill the entire record.<br><br>Change-Id: I9a5df0e46c3dd2e87d447c5c01cf15844b0eed07<br>Related: OS#4963<br>---<br>M pySim/commands.py<br>1 file changed, 13 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/commands.py b/pySim/commands.py</span><br><span>index 83ad167..48c66bd 100644</span><br><span>--- a/pySim/commands.py</span><br><span>+++ b/pySim/commands.py</span><br><span>@@ -216,13 +216,20 @@</span><br><span> </span><br><span>   def update_record(self, ef, rec_no:int, data:str, force_len:bool=False, verify:bool=False,</span><br><span>                                     conserve:bool=False):</span><br><span style="color: hsl(0, 100%, 40%);">-         r = self.select_path(ef)</span><br><span style="color: hsl(0, 100%, 40%);">-                if not force_len:</span><br><span style="color: hsl(0, 100%, 40%);">-                       rec_length = self.__record_len(r)</span><br><span style="color: hsl(0, 100%, 40%);">-                       if (len(data) // 2 != rec_length):</span><br><span style="color: hsl(0, 100%, 40%);">-                              raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data) // 2))</span><br><span style="color: hsl(0, 100%, 40%);">-            else:</span><br><span style="color: hsl(120, 100%, 40%);">+         res = self.select_path(ef)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          if force_len:</span><br><span style="color: hsl(120, 100%, 40%);">+                 # enforce the record length by the actual length of the given data input</span><br><span>                     rec_length = len(data) // 2</span><br><span style="color: hsl(120, 100%, 40%);">+           else:</span><br><span style="color: hsl(120, 100%, 40%);">+                 # determine the record length from the select response of the file and pad</span><br><span style="color: hsl(120, 100%, 40%);">+                    # the input data with 0xFF if necessary. In cases where the input data</span><br><span style="color: hsl(120, 100%, 40%);">+                        # exceed we throw an exception.</span><br><span style="color: hsl(120, 100%, 40%);">+                       rec_length = self.__record_len(res)</span><br><span style="color: hsl(120, 100%, 40%);">+                   if (len(data) // 2 > rec_length):</span><br><span style="color: hsl(120, 100%, 40%);">+                          raise ValueError('Data length exceeds record length (expected max %d, got %d)' % (rec_length, len(data) // 2))</span><br><span style="color: hsl(120, 100%, 40%);">+                        elif (len(data) // 2 < rec_length):</span><br><span style="color: hsl(120, 100%, 40%);">+                                data = rpad(data, rec_length * 2)</span><br><span> </span><br><span>                # Save write cycles by reading+comparing before write</span><br><span>                if conserve:</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/24008">change 24008</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/24008"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I9a5df0e46c3dd2e87d447c5c01cf15844b0eed07 </div>
<div style="display:none"> Gerrit-Change-Number: 24008 </div>
<div style="display:none"> Gerrit-PatchSet: 8 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>