Change in pysim[master]: commands: pad short data input in update_record()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Sun May 23 10:05:50 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/24008 )

Change subject: commands: pad short data input in update_record()
......................................................................

commands: pad short data input in update_record()

The method update_record as a "force_len" parameter, which is somewhat
irretatating. Some explainatory comments and a reformat of the if
statement will help to make it more understandable to the api user.

In the non force_len case the method determines the record length from
the select response and throws an exception if the data input does not
match that length. This makes sense if the data input exceeds the
record length of the file but if the data input is less then the record
length the situation is fixable by padding the input with 0xff. This
also a quite common case because in some situation it is not guaranteed
that the data will fill the entire record.

Change-Id: I9a5df0e46c3dd2e87d447c5c01cf15844b0eed07
Related: OS#4963
---
M pySim/commands.py
1 file changed, 13 insertions(+), 6 deletions(-)

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



diff --git a/pySim/commands.py b/pySim/commands.py
index 83ad167..48c66bd 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -216,13 +216,20 @@
 
 	def update_record(self, ef, rec_no:int, data:str, force_len:bool=False, verify:bool=False,
 					  conserve:bool=False):
-		r = self.select_path(ef)
-		if not force_len:
-			rec_length = self.__record_len(r)
-			if (len(data) // 2 != rec_length):
-				raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data) // 2))
-		else:
+		res = self.select_path(ef)
+
+		if force_len:
+			# enforce the record length by the actual length of the given data input
 			rec_length = len(data) // 2
+		else:
+			# determine the record length from the select response of the file and pad
+			# the input data with 0xFF if necessary. In cases where the input data
+			# exceed we throw an exception.
+			rec_length = self.__record_len(res)
+			if (len(data) // 2 > rec_length):
+				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)
 
 		# Save write cycles by reading+comparing before write
 		if conserve:

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/24008
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9a5df0e46c3dd2e87d447c5c01cf15844b0eed07
Gerrit-Change-Number: 24008
Gerrit-PatchSet: 8
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210523/81449dc3/attachment.htm>


More information about the gerrit-log mailing list