diff --git a/.travis.yml b/.travis.yml index 71def4b..78a1817 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ python: - 3.3 - 3.4 - 3.5 + - 3.6 + - 3.7-dev + - pypy install: - gcc --version script: python setup.py test diff --git a/README.rst b/README.rst index 47a5e49..ec5d94d 100644 --- a/README.rst +++ b/README.rst @@ -1,11 +1,24 @@ -xxtea |travis-badge| |pypi-badge| -================================== +xxtea |travis-badge| |appveyor-badge| |pypi-badge| |supported-pythons-badge| |license-badge| +============================================================================================== -.. |travis-badge| image:: https://travis-ci.org/ifduyue/xxtea.png - :target: https://travis-ci.org/ifduyue/xxtea +.. |travis-badge| image:: https://travis-ci.org/ifduyue/xxtea.svg + :target: https://travis-ci.org/ifduyue/xxtea -.. |pypi-badge| image:: https://badge.fury.io/py/xxtea.svg - :target: http://badge.fury.io/py/xxtea +.. |appveyor-badge| image:: https://ci.appveyor.com/api/projects/status/mitcnsayvbr10gt4?svg=true + :target: https://ci.appveyor.com/project/duyue/xxtea + :alt: Appveyor Build Status + +.. |pypi-badge| image:: https://img.shields.io/pypi/v/xxtea.svg + :target: https://pypi.python.org/pypi/xxtea + :alt: Latest Version + +.. |supported-pythons-badge| image:: https://img.shields.io/pypi/pyversions/xxtea.svg + :target: https://pypi.python.org/pypi/xxtea + :alt: Supported Python versions + +.. |license-badge| image:: https://img.shields.io/pypi/l/xxtea.svg + :target: https://pypi.python.org/pypi/xxtea + :alt: License .. _XXTEA: http://en.wikipedia.org/wiki/XXTEA .. _longs2bytes: https://github.com/ifduyue/xxtea/blob/master/xxtea.c#L130 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ca98151 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,37 @@ +environment: + matrix: + - PYTHON: "C:\\Python26" + - PYTHON: "C:\\Python26-x64" + - PYTHON: "C:\\Python27" + - PYTHON: "C:\\Python27-x64" + - PYTHON: "C:\\Python32" + - PYTHON: "C:\\Python32-x64" + - PYTHON: "C:\\Python33" + - PYTHON: "C:\\Python33-x64" + - PYTHON: "C:\\Python34" + - PYTHON: "C:\\Python34-x64" + - PYTHON: "C:\\Python35" + - PYTHON: "C:\\Python35-x64" + - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python36-x64" + +build: off + +install: + - git --version + - python --version + - pip install --disable-pip-version-check --user --upgrade pip + - pip install --upgrade wheel setuptools + - pip --version + +test_script: + - python setup.py test + +after_test: + - python setup.py bdist_wheel + - python setup.py bdist_wininst + - python setup.py bdist_msi + - ps: ls dist + +artifacts: + - path: dist\* diff --git a/setup.py b/setup.py index b4d90a0..5d1f6a0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, Extension import os -VERSION = "1.0.2" +VERSION = "1.1.0" if os.name == 'posix': extra_compile_args = [ @@ -49,6 +49,7 @@ 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ], setup_requires=["nose>=1.3.0"], test_suite='nose.collector', diff --git a/xxtea.c b/xxtea.c index e3425f3..f2485bd 100644 --- a/xxtea.c +++ b/xxtea.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015, Yue Du + * Copyright (c) 2014-2016, Yue Du * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -26,7 +26,6 @@ #include -#include #include #include @@ -53,9 +52,9 @@ static PyObject *_xxtea_pyunicode_unhexlify; static PyObject *_xxtea_pyunicode_decrypt; -static void btea(uint32_t *v, int n, uint32_t const key[4]) +static void btea(unsigned int *v, int n, unsigned int const key[4]) { - uint32_t y, z, sum; + unsigned int y, z, sum; unsigned p, rounds, e; if (n > 1) { /* Coding Part */ @@ -99,7 +98,7 @@ static void btea(uint32_t *v, int n, uint32_t const key[4]) } } -static int bytes2longs(const char *in, int inlen, uint32_t *out, int padding) +static int bytes2longs(const char *in, int inlen, unsigned int *out, int padding) { int i, pad; const unsigned char *s; @@ -127,7 +126,7 @@ static int bytes2longs(const char *in, int inlen, uint32_t *out, int padding) return ((i - 1) >> 2) + 1; } -static int longs2bytes(uint32_t *in, int inlen, char *out, int padding) +static int longs2bytes(unsigned int *in, int inlen, char *out, int padding) { int i, outlen, pad; unsigned char *s; @@ -188,7 +187,7 @@ static PyObject *xxtea_encrypt(PyObject *self, PyObject *args, PyObject *kwargs) int alen, dlen, klen; PyObject *retval; char *retbuf; - uint32_t *d, k[4]; + unsigned int *d, k[4]; d = NULL; retval = NULL; @@ -204,15 +203,17 @@ static PyObject *xxtea_encrypt(PyObject *self, PyObject *args, PyObject *kwargs) } alen = dlen < 4 ? 2 : (dlen >> 2) + 1; - d = (uint32_t *)calloc(alen, sizeof(uint32_t)); + d = (unsigned int *)calloc(alen, sizeof(unsigned int)); if (d == NULL) { return PyErr_NoMemory(); } + Py_BEGIN_ALLOW_THREADS bytes2longs(data, dlen, d, 1); bytes2longs(key, klen, k, 0); btea(d, alen, k); + Py_END_ALLOW_THREADS retval = PyString_FromStringAndSize(NULL, (alen << 2)); @@ -264,7 +265,7 @@ static PyObject *xxtea_decrypt(PyObject *self, PyObject *args, PyObject *kwargs) int alen, dlen, klen, rc; PyObject *retval; char *retbuf; - uint32_t *d, k[4]; + unsigned int *d, k[4]; d = NULL; retval = NULL; @@ -294,7 +295,7 @@ static PyObject *xxtea_decrypt(PyObject *self, PyObject *args, PyObject *kwargs) } alen = dlen / 4; - d = (uint32_t *)calloc(alen, sizeof(uint32_t)); + d = (unsigned int *)calloc(alen, sizeof(unsigned int)); if (d == NULL) { PyErr_NoMemory(); @@ -302,11 +303,13 @@ static PyObject *xxtea_decrypt(PyObject *self, PyObject *args, PyObject *kwargs) } + Py_BEGIN_ALLOW_THREADS bytes2longs(data, dlen, d, 0); bytes2longs(key, klen, k, 0); btea(d, -alen, k); - rc = longs2bytes(d, alen, retbuf, 1); + Py_END_ALLOW_THREADS + if (rc >= 0) { /* Remove PKCS#7 padded chars */ Py_SIZE(retval) = rc;