socksio
socksio copied to clipboard
enhance: fix bytearray might be passed into lru_cached function
Most type checkers will fit bytearray into bytes automatically. However, the former is hashable but the later is not hashable. Our decode_address is a lru_cache function and requires hashable inputs. This will trigger an exception says "unhashable type: 'bytearray'".
Example:
from socksio.socks5 import SOCKS5Reply
data = bytearray(b'\x05\x00\x00\x01\x7f\x00\x00\x01\x1e\xd2')
SOCKS5Reply.loads(bytes(data)) # OK
SOCKS5Reply.loads(data) # ValueError
Thanks for this, could we add a test case to ensure we don't regress on this behavior?
Sorry for my late reply. I've add a few code to test bytearray input in https://github.com/sethmlarson/socksio/pull/58/commits/9f992b32be9856ec5975d21f8296f5f1936d091a.