laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/35813?usp=email )

Change subject: pylint: ota.py
......................................................................

pylint: ota.py

pySim/ota.py:21:0: W0401: Wildcard import construct (wildcard-import)
pySim/ota.py:129:8: R1705: Unnecessary "elif" after "return", remove the 
leading "el" from "elif" (no-else-return)
pySim/ota.py:150:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:192:8: W0612: Unused variable 'padded_data' (unused-variable)
pySim/ota.py:202:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:207:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:210:4: C0103: Method name "fromKeyset" doesn't conform to 
snake_case naming style (invalid-name)
pySim/ota.py:239:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:242:4: C0103: Method name "fromKeyset" doesn't conform to 
snake_case naming style (invalid-name)
pySim/ota.py:328:4: W0221: Number of parameters was 4 in 
'OtaDialect.encode_cmd' and is now 5 in overriding 'OtaDialectSms.encode_cmd' 
method (arguments-differ)
pySim/ota.py:392:4: W0221: Number of parameters was 3 in 
'OtaDialect.decode_resp' and is now 4 in overriding 'OtaDialectSms.decode_resp' 
method (arguments-differ)

Change-Id: Icb8d690e541dbaf1406085a8446a0c67641fefff
---
M pySim/ota.py
1 file changed, 37 insertions(+), 18 deletions(-)

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




diff --git a/pySim/ota.py b/pySim/ota.py
index 5955a08..14bad56 100644
--- a/pySim/ota.py
+++ b/pySim/ota.py
@@ -15,14 +15,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-from pySim.construct import *
-from pySim.utils import b2h
-from pySim.sms import UserDataHeader
-from construct import *
 import zlib
 import abc
 import struct
 from typing import Optional
+from construct import Enum, Int8ub, Int16ub, Struct, Bytes, GreedyBytes, 
BitsInteger, BitStruct
+from construct import Flag, Padding, Switch, this
+
+from pySim.construct import *
+from pySim.utils import b2h
+from pySim.sms import UserDataHeader

 # ETS TS 102 225 gives the general command structure and the dialects for 
CAT_TP, TCP/IP and HTTPS
 # 3GPP TS 31.115 gives the dialects for SMS-PP, SMS-CB, USSD and HTTP
@@ -112,12 +114,12 @@
     @property
     def auth(self):
         """Return an instance of the matching OtaAlgoAuth."""
-        return OtaAlgoAuth.fromKeyset(self)
+        return OtaAlgoAuth.from_keyset(self)

     @property
     def crypt(self):
         """Return an instance of the matching OtaAlgoCrypt."""
-        return OtaAlgoCrypt.fromKeyset(self)
+        return OtaAlgoCrypt.from_keyset(self)

 class OtaCheckError(Exception):
     pass
@@ -128,26 +130,24 @@
     def _compute_sig_len(self, spi:SPI):
         if spi['rc_cc_ds'] == 'no_rc_cc_ds':
             return 0
-        elif spi['rc_cc_ds'] == 'rc': # CRC-32
+        if spi['rc_cc_ds'] == 'rc': # CRC-32
             return 4
-        elif spi['rc_cc_ds'] == 'cc': # Cryptographic Checksum (CC)
+        if spi['rc_cc_ds'] == 'cc': # Cryptographic Checksum (CC)
             # TODO: this is not entirely correct, as in AES case it could be 4 
or 8
             return 8
-        else:
-            raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds'])
+        raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds'])

     @abc.abstractmethod
-    def encode_cmd(self, otak: OtaKeyset, tar: bytes, apdu: bytes) -> bytes:
+    def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, apdu: bytes) 
-> bytes:
         pass

     @abc.abstractmethod
-    def decode_resp(self, otak: OtaKeyset, apdu: bytes) -> (object, 
Optional["CompactRemoteResp"]):
+    def decode_resp(self, otak: OtaKeyset, spi: dict, apdu: bytes) -> (object, 
Optional["CompactRemoteResp"]):
         """Decode a response into a response packet and, if indicted (by a
         response status of `"por_ok"`) a decoded response.

         The response packet's common characteristics are not fully determined,
         and (so far) completely proprietary per dialect."""
-        pass


 from Cryptodome.Cipher import DES, DES3, AES
@@ -190,7 +190,7 @@
     def encrypt(self, data:bytes) -> bytes:
         """Encrypt given input bytes using the key material given in 
constructor."""
         padded_data = self.pad_to_blocksize(data)
-        return self._encrypt(data)
+        return self._encrypt(padded_data)

     def decrypt(self, data:bytes) -> bytes:
         """Decrypt given input bytes using the key material given in 
constructor."""
@@ -199,15 +199,13 @@
     @abc.abstractmethod
     def _encrypt(self, data:bytes) -> bytes:
         """Actual implementation, to be implemented by derived class."""
-        pass

     @abc.abstractmethod
     def _decrypt(self, data:bytes) -> bytes:
         """Actual implementation, to be implemented by derived class."""
-        pass

     @classmethod
-    def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoCrypt':
+    def from_keyset(cls, otak: OtaKeyset) -> 'OtaAlgoCrypt':
         """Resolve the class for the encryption algorithm of otak and 
instantiate it."""
         for subc in cls.__subclasses__():
             if subc.enum_name == otak.algo_crypt:
@@ -239,7 +237,7 @@
         pass

     @classmethod
-    def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoAuth':
+    def from_keyset(cls, otak: OtaKeyset) -> 'OtaAlgoAuth':
         """Resolve the class for the authentication algorithm of otak and 
instantiate it."""
         for subc in cls.__subclasses__():
             if subc.enum_name == otak.algo_auth:

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35813?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: Icb8d690e541dbaf1406085a8446a0c67641fefff
Gerrit-Change-Number: 35813
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to