Skip to content

Commit

Permalink
Add a human message when initializing a Peer with private key bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Nov 26, 2024
1 parent 9f009b8 commit 446e7b9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ipv8/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def __init__(self, key: Key | bytes, address: Address | None = None, intro: bool
:param intro: is this peer suggested to us (otherwise it contacted us)
"""
if not isinstance(key, Key):
if key.startswith((b"-----BEGIN EC PRIVATE KEY-----", b"LibNaCLSK:")):
msg = ("You attempted to initialize a Peer with PRIVATE key material."
" This is normally ONLY done for your own Peer instance and internally handled by IPv8."
" If this is truly what you want to do, initialize Peer with a PrivateKey subclass.")
raise ValueError(msg)
self.key: Key = default_eccrypto.key_from_public_bin(key)
else:
self.key = cast(Key, key)
Expand Down

0 comments on commit 446e7b9

Please sign in to comment.