[Pyrex] strings, bytes, unsigned char * and the dreaded null...

Jim McCoy jim.mccoy at gmail.com
Wed Nov 15 21:10:23 UTC 2006


I am in the midst of writing a wrapper around a crypto library and
apparently I am either rustier at C than I thought or am missing some bit of
Python C api that will make this all a lot easier.

Short version of my problem is that the various library routines expect to
get keys and data as pointers to unsigned char with explicit length as an
additional arg.  This seems pretty reasonable since strings containing nulls
are rather common in crypto as both input and output.

My first thought was that things would be fairly easy in pyrex since python
strings also have no problems with embedded nulls. The various crypto
functions I am using are not changing the length of what is getting passed
to them.  After going through several iterations of ways I hoped I could
manipulate these python strings into useful pointers to the data I wanted I
am now feeling somewhat mixed up (and a bit frustrated at getting to the
point where most of my tests work and some occasionally fail....)

To assure myself that I am on the right track and get a fresh viewpoint
untainted by the various ratholes I have crawled through to get to this
point, does anyone have a suggestion for a good wrapper to my various
input/ouput needs given a pythonic side that just takes in strings (which
may contain embedded nulls like "\x00this is a key" or "\x00\x00x00\x00")
and calls a C library using the follow two functions:

setup_crypto(unsigned char *key, int keylen)
do_crypto(unsigned char *input, unsigned char *output)


Any suggestions as the "the pyrex way" regarding this would be greatly
appreciated.

Regards,

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20061115/36f04c0f/attachment.html 


More information about the Pyrex mailing list