Skip to content

Commit 9c2f687

Browse files
committed
add type annotations and pyright validation
1 parent 48a0761 commit 9c2f687

10 files changed

Lines changed: 513 additions & 427 deletions

File tree

.github/workflows/validate.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ jobs:
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip
20-
pip install black flake8 flake8-docstrings isort
20+
pip install .[develop]
2121
- name: Run flake8
2222
run: flake8
2323
- name: Run isort
2424
run: isort ./ --check
2525
- name: Run black
2626
run: black ./ --check
27+
- name: Run pyright
28+
run: pyright
2729
- name: Run test install
2830
run: pip install .

e3dc/_RSCPEncryptDecrypt.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations # required for python < 3.9
2+
13
import math
24

3-
from py3rijndael import RijndaelCbc, ZeroPadding
5+
from py3rijndael import RijndaelCbc, ZeroPadding # type: ignore
46

57
KEY_SIZE = 32
68
BLOCK_SIZE = 32
@@ -12,7 +14,7 @@ class ParameterError(Exception):
1214
pass
1315

1416

15-
def zeroPad_multiple(string, value):
17+
def zeroPad_multiple(string: bytes, value: int) -> bytes:
1618
"""Zero padding string."""
1719
length = len(string)
1820
if length % value == 0:
@@ -21,7 +23,7 @@ def zeroPad_multiple(string, value):
2123
return string.ljust(newL, b"\x00")
2224

2325

24-
def truncate_multiple(string, value):
26+
def truncate_multiple(string: bytes, value: int) -> bytes:
2527
"""Truncating sting."""
2628
length = len(string)
2729
if length % value == 0:
@@ -33,22 +35,21 @@ def truncate_multiple(string, value):
3335
class RSCPEncryptDecrypt:
3436
"""A class for encrypting and decrypting RSCP data."""
3537

36-
def __init__(self, key):
38+
def __init__(self, key: bytes):
3739
"""Constructor of a RSCP encryption and decryption class.
3840
3941
Args:
40-
key (str): RSCP encryption key
42+
key (bytes): RSCP encryption key
4143
"""
4244
if len(key) > KEY_SIZE:
4345
raise ParameterError("Key must be <%d bytes" % (KEY_SIZE))
44-
4546
self.key = key.ljust(KEY_SIZE, b"\xff")
4647
self.encryptIV = b"\xff" * BLOCK_SIZE
4748
self.decryptIV = b"\xff" * BLOCK_SIZE
4849
self.remainingData = b""
4950
self.oldDecrypt = b""
5051

51-
def encrypt(self, plainText):
52+
def encrypt(self, plainText: bytes) -> bytes:
5253
"""Method to encryt plain text."""
5354
encryptor = RijndaelCbc(
5455
self.key,
@@ -60,7 +61,9 @@ def encrypt(self, plainText):
6061
self.encryptIV = encText[-BLOCK_SIZE:]
6162
return encText
6263

63-
def decrypt(self, encText, previouslyProcessedData=None):
64+
def decrypt(
65+
self, encText: bytes, previouslyProcessedData: int | None = None
66+
) -> bytes:
6467
"""Method to decryt encrypted text."""
6568
if previouslyProcessedData is None:
6669
length = len(self.oldDecrypt)
@@ -92,4 +95,4 @@ def decrypt(self, encText, previouslyProcessedData=None):
9295
padding=ZeroPadding(BLOCK_SIZE),
9396
block_size=BLOCK_SIZE,
9497
)
95-
return decryptor.decrypt(toDecrypt)
98+
return decryptor.decrypt(toDecrypt) # pyright: ignore [reportUnknownMemberType]

e3dc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Licensed under a MIT license. See LICENSE for details.
66
"""
77

8-
from ._e3dc import E3DC, AuthenticationError, PollError
8+
from ._e3dc import E3DC, AuthenticationError, NotAvailableError, PollError, SendError
99
from ._e3dc_rscp_local import CommunicationError, RSCPAuthenticationError, RSCPKeyError
1010
from ._e3dc_rscp_web import RequestTimeoutError, SocketNotReady
1111
from ._rscpLib import FrameError

0 commit comments

Comments
 (0)