Skip to content

Commit 172fecb

Browse files
committed
Get tox working and fix python3 errors
1 parent dd5c246 commit 172fecb

8 files changed

Lines changed: 44 additions & 58 deletions

File tree

.gitignore

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
1-
# Logs
2-
logs
3-
*.log
41
*~
52
*.swp
63

7-
# Runtime data
8-
pids
9-
*.pid
10-
*.seed
114
*.pyc
125

13-
# Directory for instrumented libs generated by jscoverage/JSCover
14-
lib-cov
15-
16-
# Coverage directory used by tools like istanbul
17-
coverage
18-
19-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20-
.grunt
21-
22-
# Compiled binary addons (http://nodejs.org/api/addons.html)
23-
build/Release
24-
25-
# Dependency directory
26-
# Commenting this out is preferred by some people, see
27-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
286
node_modules
297

30-
# Users Environment Variables
31-
.lock-wscript
8+
.tox
9+
.eggs
10+
.coverage

circle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ dependencies:
99
- nodejs/node_modules
1010
pre:
1111
- cd nodejs;npm install
12-
- pip install pyelliptic cryptography
12+
- pip install tox
1313

1414
test:
1515
override:
1616
- cd nodejs;node test.js
17-
- cd python;python test.py
17+
- cd python;tox

python/http_ece/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
class ECEException(Exception):
3030
"""Exception for ECE encryption functions"""
31-
pass
31+
def __init__(self, message):
32+
self.message = message
3233

3334
# TODO: turn this into a class so that we don't grow/stomp keys.
3435

@@ -78,7 +79,7 @@ def length_prefix(key):
7879
else:
7980
raise ECEException(u"unknown 'mode' specified: " + mode)
8081
if version == "aes128gcm":
81-
context = "WebPush: info\x00" + receiver_pub_key + sender_pub_key
82+
context = b"WebPush: info\x00" + receiver_pub_key + sender_pub_key
8283
else:
8384
label = labels.get(keyid, 'P-256').encode('utf-8')
8485
context = (label + b"\0" + length_prefix(receiver_pub_key) +
@@ -192,7 +193,7 @@ def parse_content_header(content):
192193
:type content: str
193194
194195
"""
195-
id_len = struct.unpack("!B", content[20])[0]
196+
id_len = struct.unpack("!B", content[20:21])[0]
196197
return {
197198
"salt": content[:16],
198199
"rs": struct.unpack("!L", content[16:20])[0],
@@ -281,13 +282,14 @@ def encrypt(content, salt=None, key=None, keyid=None, dh=None, rs=4096,
281282
:rtype str
282283
283284
"""
284-
def encrypt_record(key, nonce, counter, buffer):
285+
def encrypt_record(key, nonce, counter, buf):
285286
encryptor = Cipher(
286287
algorithms.AES(key),
287288
modes.GCM(iv(nonce, counter)),
288289
backend=default_backend()
289290
).encryptor()
290-
data = encryptor.update(b"\0\0" + buffer) + encryptor.finalize()
291+
data = encryptor.update(b"\0\0" + buf)
292+
data += encryptor.finalize()
291293
data += encryptor.tag
292294
return data
293295

python/http_ece/tests/test_ece.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from http_ece import ECEException
1313

1414

15-
TEST_STRING = "You know my name, look up the number."
15+
TEST_STRING = b"You know my name, look up the number."
1616
TEST_LEN = len(TEST_STRING)
1717
LEGACY_FILE = os.path.join(os.sep, "..", "encrypt_data.json")[1:]
1818

python/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pyelliptic
2-
cryptography
1+
-e .

python/setup.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,10 @@
44

55
from setuptools import setup
66

7-
8-
def read_from(req_file):
9-
reply = []
10-
with io.open(os.path.join(here, req_file), encoding='utf8') as data:
11-
for l in data:
12-
l = l.strip()
13-
if not l:
14-
break
15-
if l[:2] == '-r':
16-
reply.extend(read_from(l.split(' ')[1]))
17-
continue
18-
if l[0] != '#' or l[:2] != '//':
19-
reply.append(l)
20-
return reply
21-
22-
237
here = os.path.abspath(os.path.dirname(__file__))
248
with io.open(os.path.join(here, 'README.rst'), encoding='utf8') as f:
259
README = f.read()
2610

27-
2811
setup(
2912
name='http_ece',
3013
version='0.6.0',
@@ -41,8 +24,16 @@ def read_from(req_file):
4124
'Programming Language :: Python :: 3.4',
4225
],
4326
keywords='crypto http',
44-
install_requires=read_from('requirements.txt'),
45-
tests_require=read_from('test-requirements.txt'),
27+
install_requires=[
28+
'pyelliptic',
29+
'cryptography',
30+
],
31+
tests_require=[
32+
'nose',
33+
'mock',
34+
'coverage',
35+
'flake8',
36+
],
4637
test_suite="nose.collector",
4738
url='https://github.com/martinthomson/encrypted-content-encoding',
4839
license='MIT'

python/test-requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

python/tox.ini

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Tox (http://tox.testrun.org/) is a tool for running tests
2+
# in multiple virtualenvs. This configuration file will run the
3+
# test suite on all supported python versions. To use it, "pip install tox"
4+
# and then run "tox" from this directory.
5+
6+
[tox]
7+
envlist = py27,py35
8+
9+
[testenv]
10+
basepython =
11+
py27: python2.7
12+
py35: python3.5
13+
commands =
14+
nosetests \
15+
[]
16+
deps =
17+
nose
18+
mock
19+
coverage
20+
flake8

0 commit comments

Comments
 (0)