I'm having trouble ctypes binding and ctypes docs lighten my head up a bit.
I have a remote network client sending binary data, and the library used (Mosquitto, for MQTT message brokers) provides a ctypes method to get the source binary data from the network. This is the type "LP_c_ubyte". Is there an efficient way to turn this back into a python 'str' object?
I need a regular set of bytes to use to decrypt M2Crypto functions.
pp = ''.join(chr(msg.payload[i]) for i in xrange(msg.payloadlen))
clear_text = rsa.private_decrypt(pp, M2Crypto.RSA.pkcs1_padding)
It works, but it's pretty ugly.
I can go and change the client to base64, first encode everything and then unbase64 for that purpose, but this also seems like a workaround.
Are there any better ways?
source
share