Skip to content

Commit 5d59850

Browse files
mdhomvchrisb
andauthored
Raise RSCPKeyError if invalid RSCP key given (#60)
* directly raising RSCPAuthenticationError if empty data received * add RSCPKeyError exception --------- Co-authored-by: Christopher Banck <vchrisb@users.noreply.github.com>
1 parent 8ab3706 commit 5d59850

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

e3dc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from ._e3dc import E3DC, AuthenticationError, PollError
9-
from ._e3dc_rscp_local import CommunicationError, RSCPAuthenticationError
9+
from ._e3dc_rscp_local import CommunicationError, RSCPAuthenticationError, RSCPKeyError
1010
from ._e3dc_rscp_web import RequestTimeoutError, SocketNotReady
1111
from ._rscpLib import FrameError
1212
from ._rscpLib import set_debug as set_rscp_debug
@@ -17,6 +17,7 @@
1717
"PollError",
1818
"CommunicationError",
1919
"RSCPAuthenticationError",
20+
"RSCPKeyError",
2021
"RequestTimeoutError",
2122
"SocketNotReady",
2223
"FrameError",

e3dc/_e3dc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ._e3dc_rscp_local import (
1818
E3DC_RSCP_local,
1919
RSCPAuthenticationError,
20+
RSCPKeyError,
2021
RSCPNotAvailableError,
2122
)
2223
from ._e3dc_rscp_web import E3DC_RSCP_web
@@ -524,6 +525,8 @@ def sendRequest(self, request, retries=3, keepAlive=False):
524525
raise AuthenticationError()
525526
except RSCPNotAvailableError:
526527
raise NotAvailableError()
528+
except RSCPKeyError:
529+
raise
527530
except Exception:
528531
retry += 1
529532
if retry > retries:

e3dc/_e3dc_rscp_local.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class RSCPNotAvailableError(Exception):
2525
pass
2626

2727

28+
class RSCPKeyError(Exception):
29+
"""Class for RSCP Encryption Key Error Exception."""
30+
31+
pass
32+
33+
2834
class CommunicationError(Exception):
2935
"""Class for Communication Error Exception."""
3036

@@ -58,6 +64,8 @@ def _send(self, plainMsg):
5864

5965
def _receive(self):
6066
data = self.socket.recv(BUFFER_SIZE)
67+
if len(data) == 0:
68+
return None
6169
decData = rscpDecode(self.encdec.decrypt(data))[0]
6270
return decData
6371

@@ -85,6 +93,9 @@ def sendRequest(self, plainMsg):
8593
self.disconnect()
8694
raise CommunicationError
8795

96+
if receive is None:
97+
raise RSCPKeyError
98+
8899
if receive[1] == "Error":
89100
self.disconnect()
90101
if receive[2] == "RSCP_ERR_ACCESS_DENIED":

0 commit comments

Comments
 (0)