[M] Change in pysim[master]: saip.personalization: differentiate input_value from value

2024-02-22 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/36016?usp=email )

Change subject: saip.personalization: differentiate input_value from value
..

saip.personalization: differentiate input_value from value

When personalizing e.g. the ICCID, the input_value is the raw
incrementing counter.  From that, we calculate the Luhn check digit,
and that "output" value is what we'll put in to the EF.ICCID specific
encoder.

However, we also store that output value in the instance in order
to generate the output CSV file containig the card-specific
personalization data.

Change-Id: Idfcd26c8ca9d73a9c2955f7c97e711dd59a27c4e
---
M pySim/esim/saip/personalization.py
1 file changed, 50 insertions(+), 20 deletions(-)

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




diff --git a/pySim/esim/saip/personalization.py 
b/pySim/esim/saip/personalization.py
index 84baddb..7ac0dbd 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -46,13 +46,15 @@
 class ConfigurableParameter(abc.ABC, metaclass=ClassVarMeta):
 """Base class representing a part of the eSIM profile that is configurable 
during the
 personalization process (with dynamic data from elsewhere)."""
-def __init__(self, value):
-self.value = value
+def __init__(self, input_value):
+self.input_value = input_value # the raw input value as given by caller
+self.value = None # the processed input value (e.g. with check digit) 
as produced by validate()

 def validate(self):
 """Optional validation method. Can be used by derived classes to 
perform validation
 of the input value (self.value).  Will raise an exception if 
validation fails."""
-pass
+# default implementation: simply copy input_value over to value
+self.value = self.input_value

 @abc.abstractmethod
 def apply(self, pes: ProfileElementSequence):
@@ -65,18 +67,18 @@

 def validate(self):
 # convert to string as it migt be an integer
-iccid_str = str(self.value)
+iccid_str = str(self.input_value)
 if len(iccid_str) < 18 or len(iccid_str) > 20:
 raise ValueError('ICCID must be 18, 19 or 20 digits long')
 if not iccid_str.isdecimal():
 raise ValueError('ICCID must only contain decimal digits')
+self.value = sanitize_iccid(iccid_str)

 def apply(self, pes: ProfileElementSequence):
-iccid_str = sanitize_iccid(self.value)
 # patch the header
-pes.get_pe_for_type('header').decoded['iccid'] = iccid_str
+pes.get_pe_for_type('header').decoded['iccid'] = self.value
 # patch MF/EF.ICCID
-file_replace_content(pes.get_pe_for_type('mf').decoded['ef-iccid'], 
h2b(enc_iccid(iccid_str)))
+file_replace_content(pes.get_pe_for_type('mf').decoded['ef-iccid'], 
h2b(enc_iccid(self.value)))

 class Imsi(ConfigurableParameter):
 """Configurable IMSI. Expects value to be a string of digits. 
Automatically sets the ACC to
@@ -85,14 +87,15 @@

 def validate(self):
 # convert to string as it migt be an integer
-imsi_str = str(self.value)
+imsi_str = str(self.input_value)
 if len(imsi_str) < 6 or len(imsi_str) > 15:
 raise ValueError('IMSI must be 6..15 digits long')
 if not imsi_str.isdecimal():
 raise ValueError('IMSI must only contain decimal digits')
+self.value = imsi_str

 def apply(self, pes: ProfileElementSequence):
-imsi_str = str(self.value)
+imsi_str = self.value
 # we always use the least significant byte of the IMSI as ACC
 acc = (1 << int(imsi_str[-1]))
 # patch ADF.USIM/EF.IMSI
@@ -112,11 +115,12 @@
 permitted_len = None

 def validate(self):
-if not isinstance(self.value, (io.BytesIO, bytes, bytearray)):
+if not isinstance(self.input_value, (io.BytesIO, bytes, bytearray)):
 raise ValueError('Value must be of bytes-like type')
 if self.permitted_len:
-if len(self.value) not in self.permitted_len:
+if len(self.input_value) not in self.permitted_len:
 raise ValueError('Value length must be %s' % 
self.permitted_len)
+self.value = self.input_value

 def _apply_sd(self, pe: ProfileElement):
 assert pe.type == 'securityDomain'
@@ -208,8 +212,10 @@
 """Configurable PUK (Pin Unblock Code). String ASCII-encoded digits."""
 keyReference = None
 def validate(self):
-if isinstance(self.value, int):
-self.value = '%08d' % self.value
+if isinstance(self.input_value, int):
+self.value = '%08d' % self.input_value
+else:
+self.value = self.input_value
 # FIXME: valid length?
 if not self.value.isdecimal():
 raise ValueError('PUK must 

[M] Change in pysim[master]: saip.personalization: differentiate input_value from value

2024-02-22 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/36016?usp=email )

Change subject: saip.personalization: differentiate input_value from value
..


Patch Set 4: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/pysim/+/36016?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idfcd26c8ca9d73a9c2955f7c97e711dd59a27c4e
Gerrit-Change-Number: 36016
Gerrit-PatchSet: 4
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Comment-Date: Thu, 22 Feb 2024 10:23:30 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


[M] Change in pysim[master]: saip.personalization: differentiate input_value from value

2024-02-21 Thread laforge
Attention is currently required from: laforge.

Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/pysim/+/36016?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder


Change subject: saip.personalization: differentiate input_value from value
..

saip.personalization: differentiate input_value from value

When personalizing e.g. the ICCID, the input_value is the raw
incrementing counter.  From that, we calculate the Luhn check digit,
and that "output" value is what we'll put in to the EF.ICCID specific
encoder.

However, we also store that output value in the instance in order
to generate the output CSV file containig the card-specific
personalization data.

Change-Id: Idfcd26c8ca9d73a9c2955f7c97e711dd59a27c4e
---
M pySim/esim/saip/personalization.py
1 file changed, 50 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/16/36016/4
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/36016?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idfcd26c8ca9d73a9c2955f7c97e711dd59a27c4e
Gerrit-Change-Number: 36016
Gerrit-PatchSet: 4
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Attention: laforge 
Gerrit-MessageType: newpatchset