def test_Compat(self): assert (isinstance(a2b_hex("00"), bytearray)) assert (a2b_hex("0102cdef") == bytearray([0x01, 0x02, 0xcd, 0xef])) assert (a2b_hex("0102CDEF") == bytearray([0x01, 0x02, 0xcd, 0xef])) try: assert (a2b_hex("c0102cdef") == bytearray([0x01, 0x02, 0xcd, 0xef])) assert False except SyntaxError: pass try: assert (a2b_hex("xx0102cdef") == bytearray( [0x01, 0x02, 0xcd, 0xef])) assert False except SyntaxError: pass assert (isinstance(a2b_base64("0000"), bytearray)) assert (a2b_base64("Zm9vYg==") == bytearray(b"foob")) assert (b2a_hex(bytearray([0x01, 0x02, 0xcd, 0xef])) == "0102cdef") assert (b2a_hex(bytearray([0x00])) == "00") assert (b2a_hex(bytearray([0xFF])) == "ff") assert (b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n") assert (b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n") assert (b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n") assert (bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
def test_Compat(self): assert(isinstance(a2b_hex("00"), bytearray)) assert(a2b_hex("0102cdef") == bytearray([0x01,0x02,0xcd,0xef])) assert(a2b_hex("0102CDEF") == bytearray([0x01,0x02,0xcd,0xef])) try: assert(a2b_hex("c0102cdef") == bytearray([0x01,0x02,0xcd,0xef])) assert False except SyntaxError: pass try: assert(a2b_hex("xx0102cdef") == bytearray([0x01,0x02,0xcd,0xef])) assert False except SyntaxError: pass assert(isinstance(a2b_base64("0000"), bytearray)) assert(a2b_base64("Zm9vYg==") == bytearray(b"foob")) assert(b2a_hex(bytearray([0x01,0x02,0xcd,0xef])) == "0102cdef") assert(b2a_hex(bytearray([0x00])) == "00") assert(b2a_hex(bytearray([0xFF])) == "ff") assert(b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n") assert(b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n") assert(b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n") assert(bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
def writeBytes(b): """Write hex-encoded byte array with 16 bytes (32 chars) per line""" s = b2a_hex(b) retVal = "" while s: retVal += s[:32] s = s[32:] if len(s): retVal += "\n " return retVal