Change in pysim[master]: commands: add features to verify data written to files

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 17 18:55:29 UTC 2020


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

Change subject: commands: add features to verify data written to files
......................................................................

commands: add features to verify data written to files

When writing to files we often just write without making sure that the
actual file contents actually written. Lets add features to do a
read-after-write verification when writing to files.

Change-Id: I7be842004102f4998af376790c97647c107be3d5
---
M pySim/commands.py
1 file changed, 20 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/pySim/commands.py b/pySim/commands.py
index 30e995c..e077289 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -122,10 +122,18 @@
 		pdu = self.cla_byte + 'b0%04x%02x' % (offset, (min(256, length) & 0xff))
 		return self._tp.send_apdu(pdu)
 
-	def update_binary(self, ef, data, offset=0):
+	def update_binary(self, ef, data, offset=0, verify=False):
 		self.select_file(ef)
 		pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data) // 2) + data
-		return self._tp.send_apdu_checksw(pdu)
+		res = self._tp.send_apdu_checksw(pdu)
+		if verify:
+			self.verify_binary(ef, data, offset)
+		return res
+
+	def verify_binary(self, ef, data, offset=0):
+		res = self.read_binary(ef, len(data) // 2, offset)
+		if res[0].lower() != data.lower():
+			raise ValueError('Binary verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
 
 	def read_record(self, ef, rec_no):
 		r = self.select_file(ef)
@@ -133,7 +141,7 @@
 		pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length)
 		return self._tp.send_apdu(pdu)
 
-	def update_record(self, ef, rec_no, data, force_len=False):
+	def update_record(self, ef, rec_no, data, force_len=False, verify=False):
 		r = self.select_file(ef)
 		if not force_len:
 			rec_length = self.__record_len(r)
@@ -142,7 +150,15 @@
 		else:
 			rec_length = len(data) // 2
 		pdu = (self.cla_byte + 'dc%02x04%02x' % (rec_no, rec_length)) + data
-		return self._tp.send_apdu_checksw(pdu)
+		res = self._tp.send_apdu_checksw(pdu)
+		if verify:
+			self.verify_record(ef, rec_no, data)
+		return res
+
+	def verify_record(self, ef, rec_no, data):
+		res = self.read_record(ef, rec_no)
+		if res[0].lower() != data.lower():
+			raise ValueError('Record verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
 
 	def record_size(self, ef):
 		r = self.select_file(ef)

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7be842004102f4998af376790c97647c107be3d5
Gerrit-Change-Number: 18211
Gerrit-PatchSet: 4
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200517/22d34691/attachment.htm>


More information about the gerrit-log mailing list