pynacl

Python wrapper for http://nacl.cace-project.eu/
git clone https://code.literati.org/pynacl.git
Log | Files | Refs | README

commit f4b8c1276287356c61be1642dc264a547909a38b
parent 9d191d8a3f19a98f9521365c94976a9a0a3c8d41
Author: Sean Lynch <seanl@literati.org>
Date:   Sun, 12 Jun 2011 22:49:27 -0700

Add docs and move paths to environment variables.

Diffstat:
AREADME.md | 42++++++++++++++++++++++++++++++++++++++++++
Msetup.py | 41+++++++++++++++++++++++++++++++----------
2 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,42 @@ +PyNaCl: A Python Wrapper for NaCl +======================== + +Overview +-------- + +This is a simple wrapper for the [NaCl](http://nacl.cace-project.eu/) +cryptographic library (not Google's NativeClient). It currently wraps +crypto\_hash\_sha256, crypto\_hash\_sha512, crypto\_randombytes, and +the crypto\_box, crypto\_sign, crypto\_secretbox, and crypto\_stream +default primitives. + + +API +--- + +The API is a very straightforward translation of NaCl's C API. Any +function that returns an error code will raise ValueError if it +returns anything but zero. Output arguments are returned, with keypair +functions returning 2-tuples and everything else returning +strings. The wrapper handles all padding, so you can just ignore that +part of NaCl's documentation. + +Eventually I'll translate the documentation over, but for now look at +test.py and the [NaCl documentation](http://nacl.cace-project.eu/). + + +Installation +---------- + +First, download and build NaCl. Then: + + export NACL_LIB=<location of libnacl.a and randombytes.o, required> + export NACL_INCLUDE=<location of NaCl header files> + python setup.py build_ext + sudo python setup.py install + + +Testing +------- + +To run the tests, just run the script "test.py" in the distribution directory. diff --git a/setup.py b/setup.py @@ -1,25 +1,46 @@ #!/usr/bin/env python - -""" -Documentation! """ +Build and install the NaCl wrapper. + +Environment variables: -NACL_INCLUDE = '/Users/seanl/src/nacl-20110221/build/seanlMBP13/include/amd64' -NACL_LIB = '/Users/seanl/src/nacl-20110221/build/seanlMBP13/lib/amd64' +NACL_INCLUDE - location of NaCl's include files. Not needed if they're + in a normal system location. +NACL_LIB - location of libnacl.(a|dll) and randombytes.o. Probably + needed no matter what because of how we find randombytes.o. + +""" +import os from distutils.core import setup, Extension +include_dirs = [] +library_dirs = [] + +NACL_INCLUDE = os.environ.get('NACL_INCLUDE') + +if NACL_INCLUDE is not None: + include_dirs.append(NACL_INCLUDE) + +NACL_LIB = os.environ.get('NACL_LIB') + +if NACL_LIB is not None: + library_dirs.append(NACL_LIB) + extra_objects = ['{0}/randombytes.o'.format(NACL_LIB)] +else: + # This probably won't work. + extra_objects = ['randombytes.o'] + nacl_module = Extension('_nacl', ['nacl.i'], - include_dirs=[NACL_INCLUDE], - library_dirs=[NACL_LIB], + include_dirs=include_dirs, + library_dirs=library_dirs, libraries=['nacl'], - extra_objects=['{0}/randombytes.o'.format(NACL_LIB)], - swig_opts=['-I{0}'.format(NACL_INCLUDE)]) + extra_objects=extra_objects) setup (name = 'nacl', version = '0.1', author = "Sean Lynch", description = """Python wrapper for NaCl""", ext_modules = [nacl_module], - py_modules = ["nacl", "test"]) + py_modules = ["nacl"])