Skip to content

Commit

Permalink
Fix is_bencoded
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman committed Dec 13, 2024
1 parent 4f0ac1e commit 931664c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tribler/core/tunnel/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ def is_bencoded(x: bytes) -> bool:
"""
Returns True is x appears to be valid bencoded byte string.
"""
return bdecode(x) is not None
if not isinstance(x, bytes):
msg = f'Expected bytes, got {type(x).__name__}'
raise TypeError(msg)
try:
decoded = bdecode(x)
except RuntimeError:
decoded = None
return decoded is not None


class TriblerTunnelSettings(HiddenTunnelSettings):
Expand Down

0 comments on commit 931664c

Please sign in to comment.