My goal is to get a 64 characters long hex number from a user (which represent a serial number) and convert to c_type 32bytes number. Serial Number is defined like this:
_sn = c_ubyte * 32
I accept SN string from user into args.sn variable. Here's how I managed to solve it. I'm sure there is an easier and more elegant way, would appreciate your help.
SN_List= []
for i in range(0,len(args.sn),2):
myByte = args.sn[i: i+2]
num = int("0x" + myByte,16)
SN_List.append(num)
if(len(SN_List) != 32):
print("S/N is not valid, it should be 64 hex characters long")
return 1
_sn = (c_ubyte * 32)(*SN_List)
binascii.a2b_hex?"0x" +and the, 16; one or the other will do.