621def check_hex(hex, bytes_size = None):
622 assert hex is not None, "Error: Missing hex string"
623 size = len(hex)
624 assert size > 0, "Error: hex string is empty"
625 assert size % 2 == 0, "Error: invalid size of hex string"
626 if bytes_size is not None:
627 n = int(size / 2)
628 assert n == bytes_size, "Error: invalid number of bytes %d, expected %d" % (n, bytes_size)
629