pySim-prog: generate a pin_adm from pin_adm_hex also for CSV files

When reading CSV files we currently have no option to provide a
pin_adm_hex field like we already have it as commandline option.
Lets add an option pin_adm_hex for this.

Change-Id: I53e8d666d26a06f580725a8443a335643d10192c
diff --git a/pySim-prog.py b/pySim-prog.py
index 8abce0a..13e8bb5 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -485,6 +485,21 @@
 			pin_adm = ''.join(['%02x'%(ord(x)) for x in row['adm1']])
 		if pin_adm:
 			row['pin_adm'] = rpad(pin_adm, 16)
+
+		# If the CSV-File defines a pin_adm_hex field use this field to
+		# generate pin_adm from that.
+		pin_adm_hex = row.get('pin_adm_hex')
+		if pin_adm_hex:
+			if len(pin_adm_hex) == 16:
+				row['pin_adm'] = pin_adm_hex
+				# Ensure that it's hex-encoded
+				try:
+					try_encode = h2b(pin_adm)
+				except ValueError:
+					raise ValueError("pin_adm_hex needs to be hex encoded using this option")
+			else:
+				raise ValueError("pin_adm_hex needs to be exactly 16 digits (hex encoded)")
+
 	return row