Skip to content
Snippets Groups Projects
Commit 26b16364 authored by Donald Stufft's avatar Donald Stufft
Browse files

Merge pull request #3 from dstufft/only-support-libsodium

Remove support for libnacl leaving only libsodium
parents 6eef06aa 7d494e9b
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,11 @@ python: ...@@ -8,13 +8,11 @@ python:
install: install:
- sudo apt-get -q install python-pip - sudo apt-get -q install python-pip
- sudo /usr/bin/pip -q install git+git://github.com/pyinvoke/invoke.git - sudo /usr/bin/pip -q install git+git://github.com/pyinvoke/invoke.git
- invoke install-nacl --library=$NACL - invoke install.sodium
- invoke install --dev - invoke install.requirements --dev
script: script:
- invoke tests - invoke tests
env: env:
global: global:
- LD_LIBRARY_PATH=/usr/local/lib - LD_LIBRARY_PATH=/usr/local/lib
- LD_RUN_PATH=/usr/local/lib - LD_RUN_PATH=/usr/local/lib
matrix:
- NACL=libsodium
...@@ -3,7 +3,7 @@ CFFI interface to NaCl and libsodium library ...@@ -3,7 +3,7 @@ CFFI interface to NaCl and libsodium library
""" """
import functools import functools
from cffi import FFI, VerificationError from cffi import FFI
__all__ = ["ffi", "lib"] __all__ = ["ffi", "lib"]
...@@ -31,27 +31,6 @@ ffi.cdef( ...@@ -31,27 +31,6 @@ ffi.cdef(
) )
# Check to make sure that we have a compiled interface to one of our library
# backends. We prefer NaCl here because it has compiled speed ups.
# TODO: Include some way to specify which backend you want and hard fail if
# that one doesn't exist?
try:
# Try to compile the ffi interface with NaCl
lib = ffi.verify(
"""
#include "crypto_hash.h"
#include "crypto_hash_sha256.h"
#include "crypto_hash_sha512.h"
"""
# Secure Random
"""
#include "randombytes.h"
""",
libraries=["nacl"],
)
except VerificationError:
# Try to compile the ffi interface with libsodium if NaCl wasn't available
lib = ffi.verify("#include <sodium.h>", libraries=["sodium"]) lib = ffi.verify("#include <sodium.h>", libraries=["sodium"])
......
...@@ -5,77 +5,50 @@ import urllib2 ...@@ -5,77 +5,50 @@ import urllib2
from invoke import task, run from invoke import task, run
def download(url, hash, path): LIBSODIUM_VERSION = "0.2"
resp = urllib2.urlopen(url) LIBSODIUM_URL = "http://download.dnscrypt.org/libsodium/releases/libsodium-0.2.tar.gz"
content = resp.read() LIBSODIUM_HASH = b"e99a6b69adc080a5acf6b8a49fdc74b61d6f3579b590e85c93446a8325dde100"
content_hash = hashlib.sha256(content).hexdigest()
assert hash == content_hash
with open(path, "wb") as fp:
fp.write(content)
@task(aliases=["install-nacl"]) @task(aliases=["install.sodium"])
def install_nacl(library): def install_sodium():
def _install_libsodium(): tarball_path = os.path.expanduser(
tarball_path = os.path.expanduser("~/libsodium-0.2.tar.gz") "~/libsodium-{}.tar.gz".format(LIBSODIUM_VERSION),
# Download libsodium and verify it's hash
download(
"http://download.dnscrypt.org/libsodium/releases/libsodium-0.2.tar.gz",
"e99a6b69adc080a5acf6b8a49fdc74b61d6f3579b590e85c93446a8325dde100",
tarball_path,
) )
curdir = os.getcwd() # Download libsodium and verify it's hash
try: resp = urllib2.urlopen(LIBSODIUM_URL)
os.chdir(os.path.expanduser("~/")) content = resp.read()
content_hash = hashlib.sha256(content).hexdigest()
# Unpack the tarball
run("tar xf libsodium-0.2.tar.gz")
# Configure and install the library
os.chdir(os.path.expanduser("~/libsodium-0.2/"))
run("./configure --disable-debug --disable-dependency-tracking", hide="out")
run("make", hide="out")
run("sudo make install", hide="out")
finally:
os.chdir(curdir)
def _install_nacl(): if content_hash != LIBSODIUM_HASH:
tarball_path = os.path.expanduser("~/nacl-20110221.tar.bz2") raise ValueError("Hash mismatch for downloaded libsodium")
# Download libnacl and verify it's hash with open(tarball_path, "wb") as fp:
download( fp.write(content)
"http://hyperelliptic.org/nacl/nacl-20110221.tar.bz2",
"4f277f89735c8b0b8a6bbd043b3efb3fa1cc68a9a5da6a076507d067fc3b3bf8",
tarball_path,
)
curdir = os.getcwd() curdir = os.getcwd()
try: try:
os.chdir(os.path.expanduser("~/")) os.chdir(os.path.expanduser("~/"))
# Unpack the tarball # Unpack the tarball
run("tar xf nacl-20110221.tar.bz2", hide="out") run("tar xf libsodium-{}.tar.gz".format(LIBSODIUM_VERSION))
# Configure and install the library # Configure and install the library
os.chdir(os.path.expanduser("~/nacl-20110221/")) os.chdir(os.path.expanduser(
run("sudo ./do", hide="out") "~/libsodium-{}/".format(LIBSODIUM_VERSION),
))
run("./configure --disable-debug --disable-dependency-tracking",
hide="out",
)
run("make", hide="out")
run("sudo make install", hide="out")
finally: finally:
os.chdir(curdir) os.chdir(curdir)
libraries = {
"libsodium": _install_libsodium,
"nacl": _install_nacl,
}
# Install the library @task(aliases=["install.requirements"])
libraries[library]() def install_requirements(dev=False):
@task
def install(dev=False):
if dev: if dev:
# Install once to get the tests extra # Install once to get the tests extra
run("pip install file://$PWD#egg=pynacl[tests]", hide="out") run("pip install file://$PWD#egg=pynacl[tests]", hide="out")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment