Skip to content

Commit ad67c55

Browse files
committed
Added exception when trying to remember an invalid public key
1 parent d68cfaa commit ad67c55

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

RNS/Identity.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class Identity:
5050

5151
@staticmethod
5252
def remember(packet_hash, destination_hash, public_key, app_data = None):
53-
Identity.known_destinations[destination_hash] = [time.time(), packet_hash, public_key, app_data]
53+
if len(public_key) != Identity.KEYSIZE//8:
54+
raise TypeError("Can't remember "+RNS.prettyhexrep(destination_hash)+", the public key size of "+str(len(public_key))+" is not valid.", RNS.LOG_ERROR)
55+
else:
56+
Identity.known_destinations[destination_hash] = [time.time(), packet_hash, public_key, app_data]
5457

5558

5659
@staticmethod
@@ -339,7 +342,7 @@ def to_file(self, path):
339342
"""
340343
try:
341344
with open(path, "wb") as key_file:
342-
key_file.write(self.prv_bytes)
345+
key_file.write(self.get_public_key())
343346
return True
344347
return False
345348
except Exception as e:

0 commit comments

Comments
 (0)