Skip to content

Commit ca11bcb

Browse files
authored
Merge pull request #145 from tomato42/hypothesis
testing with hypothesis
2 parents 3538d44 + 62f0f9b commit ca11bcb

File tree

10 files changed

+329
-90
lines changed

10 files changed

+329
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ coverage-html
3333
.tox
3434
nosetests.xml
3535
t/
36+
.hypothesis/
3637

3738
# Translations
3839
*.mo

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,12 @@ script:
8787
instrumental -f .instrumental.cov -s
8888
instrumental -f .instrumental.cov -s | python diff-instrumental.py --save .diff-instrumental
8989
git checkout $BRANCH
90-
files="$(ls src/ecdsa/test*.py | grep -v test_malformed_sigs.py)"
91-
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
90+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` src/ecdsa
9291
instrumental -f .instrumental.cov -sr
9392
fi
9493
- |
9594
if [[ $INSTRUMENTAL && $TRAVIS_PULL_REQUEST == "false" ]]; then
96-
# exclude the super slow test_malformed_sigs.py, until #127 is merged
97-
files="$(ls src/ecdsa/test*.py | grep -v test_malformed_sigs.py)"
98-
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
95+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` src/ecdsa
9996
instrumental -f .instrumental.cov -s
10097
# just log the values when merging
10198
instrumental -f .instrumental.cov -s | python diff-instrumental.py

build-requirements-2.6.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tox
22
coveralls<1.3.0
33
idna<2.8
44
unittest2
5+
hypothesis<3

build-requirements-3.3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ pluggy<0.6
33
tox<3
44
wheel<0.30
55
virtualenv==15.2.0
6+
enum34
7+
hypothesis<3.44

build-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
tox
22
python-coveralls
3+
hypothesis
4+
pytest>=4.6.0

src/ecdsa/curves.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
# will need to mark it as deprecated later
99
__all__ = ["UnknownCurveError", "orderlen", "Curve", "NIST192p",
1010
"NIST224p", "NIST256p", "NIST384p", "NIST521p", "curves",
11-
"find_curve"]
11+
"find_curve", "SECP256k1"]
1212

1313

1414
class UnknownCurveError(Exception):
1515
pass
1616

1717

18-
# the NIST curves
1918
class Curve:
2019
def __init__(self, name, curve, generator, oid, openssl_name=None):
2120
self.name = name
@@ -29,25 +28,41 @@ def __init__(self, name, curve, generator, oid, openssl_name=None):
2928
self.oid = oid
3029
self.encoded_oid = der.encode_oid(*oid)
3130

31+
def __repr__(self):
32+
return self.name
33+
34+
35+
# the NIST curves
3236
NIST192p = Curve("NIST192p", ecdsa.curve_192,
3337
ecdsa.generator_192,
3438
(1, 2, 840, 10045, 3, 1, 1), "prime192v1")
39+
40+
3541
NIST224p = Curve("NIST224p", ecdsa.curve_224,
3642
ecdsa.generator_224,
3743
(1, 3, 132, 0, 33), "secp224r1")
44+
45+
3846
NIST256p = Curve("NIST256p", ecdsa.curve_256,
3947
ecdsa.generator_256,
4048
(1, 2, 840, 10045, 3, 1, 7), "prime256v1")
49+
50+
4151
NIST384p = Curve("NIST384p", ecdsa.curve_384,
4252
ecdsa.generator_384,
4353
(1, 3, 132, 0, 34), "secp384r1")
54+
55+
4456
NIST521p = Curve("NIST521p", ecdsa.curve_521,
4557
ecdsa.generator_521,
4658
(1, 3, 132, 0, 35), "secp521r1")
59+
60+
4761
SECP256k1 = Curve("SECP256k1", ecdsa.curve_secp256k1,
4862
ecdsa.generator_secp256k1,
4963
(1, 3, 132, 0, 10), "secp256k1")
5064

65+
5166
curves = [NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1]
5267

5368

src/ecdsa/der.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def encode_integer(r):
2323
s = binascii.unhexlify(h)
2424
num = str_idx_as_int(s, 0)
2525
if num <= 0x7f:
26-
return b("\x02") + int2byte(len(s)) + s
26+
return b("\x02") + encode_length(len(s)) + s
2727
else:
2828
# DER integers are two's complement, so if the first byte is
2929
# 0x80-0xff then we need an extra 0x00 byte to prevent it from
3030
# looking negative.
31-
return b("\x02") + int2byte(len(s)+1) + b("\x00") + s
31+
return b("\x02") + encode_length(len(s)+1) + b("\x00") + s
3232

3333

3434
# sentry object to check if an argument was specified (used to detect

src/ecdsa/keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ def __init__(self, _error__please_use_generate=None):
135135
self.default_hashfunc = None
136136
self.pubkey = None
137137

138+
def __repr__(self):
139+
pub_key = self.to_string("compressed")
140+
return "VerifyingKey.from_string({0!r}, {1!r}, {2})".format(
141+
pub_key, self.curve, self.default_hashfunc().name)
142+
138143
@classmethod
139144
def from_public_point(cls, point, curve=NIST192p, hashfunc=sha1):
140145
"""

0 commit comments

Comments
 (0)