I am trying to use struct.pack to pack a hash disgest, but not getting the expected result.
This is how I am packing the data:
hash = hashlib.sha256(input).digest()
print('hash = ', hash.hex())
packed = struct.pack('!32p', hash)
print('packed = ', packed.hex())
Here is an example result: hash = b5dbdb2b0a7d762fc7e429062d64b711d240e8f95f1c59fc28c28ac6677ffeaf
packed = 1fb5dbdb2b0a7d762fc7e429062d64b711d240e8f95f1c59fc28c28ac6677ffe
The bytes appear to be shifted, and "1f" has been added. Is this a result of an incorrect format specifier?
EDIT: I believe this first byte is the length of the data, because I am using 'p'. Is there any way to avoid this? I don't want to include this in my packed data