mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
check key size in _validate_destination
This commit is contained in:
parent
26b8f2b340
commit
6b24bb7c7f
1 changed files with 4 additions and 0 deletions
|
|
@ -32,10 +32,14 @@ def _validate_destination(dst: DestinationType, prefix_length: int = 6) -> bytes
|
|||
"""
|
||||
if isinstance(dst, bytes):
|
||||
# Already bytes, use directly
|
||||
if len(dst)<prefix_length:
|
||||
raise ValueError(f"Invalid prefix len, expecting {prefix_length}, got {len(dst)}")
|
||||
return dst[:prefix_length]
|
||||
elif isinstance(dst, str):
|
||||
# Hex string, convert to bytes
|
||||
try:
|
||||
if len(dst)<2*prefix_length:
|
||||
raise ValueError(f"Invalid prefix len, expecting {prefix_length}, got {len(dst)/2}")
|
||||
return bytes.fromhex(dst)[:prefix_length]
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid public key hex string: {dst}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue