mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
check key size in _validate_destination
This commit is contained in:
@@ -32,10 +32,14 @@ def _validate_destination(dst: DestinationType, prefix_length: int = 6) -> bytes
|
|||||||
"""
|
"""
|
||||||
if isinstance(dst, bytes):
|
if isinstance(dst, bytes):
|
||||||
# Already bytes, use directly
|
# 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]
|
return dst[:prefix_length]
|
||||||
elif isinstance(dst, str):
|
elif isinstance(dst, str):
|
||||||
# Hex string, convert to bytes
|
# Hex string, convert to bytes
|
||||||
try:
|
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]
|
return bytes.fromhex(dst)[:prefix_length]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError(f"Invalid public key hex string: {dst}")
|
raise ValueError(f"Invalid public key hex string: {dst}")
|
||||||
|
|||||||
Reference in New Issue
Block a user