aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-03-23 19:23:43 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-03-23 19:23:43 -0500
commita5c6e9a89242bb42dbc98f29681d2f74aec12b02 (patch)
tree57b2686b8455a561dc2a5f3d2d2a263e46cb1da2
parent58b756969211e2972fb6fda44582e55b98c02924 (diff)
downloadcryptography-a5c6e9a89242bb42dbc98f29681d2f74aec12b02.tar.gz
cryptography-a5c6e9a89242bb42dbc98f29681d2f74aec12b02.tar.bz2
cryptography-a5c6e9a89242bb42dbc98f29681d2f74aec12b02.zip
use kwargs for BasicConstraints creation
Also check path_length using integer_types
-rw-r--r--src/cryptography/x509.py7
-rw-r--r--tests/test_x509_ext.py18
2 files changed, 14 insertions, 11 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 0c773dac..43ece920 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -176,8 +176,11 @@ class BasicConstraints(object):
if path_length is not None and not ca:
raise ValueError("path_length must be None when ca is False")
- if path_length is not None and (not isinstance(path_length, int)
- or path_length < 0):
+ if (
+ path_length is not None and (not isinstance(
+ path_length, six.integer_types
+ ) or path_length < 0)
+ ):
raise TypeError(
"path_length must be a non-negative integer or None"
)
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index de3ca312..74d14c57 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -11,17 +11,17 @@ from cryptography import x509
class TestExtension(object):
def test_not_an_oid(self):
- bc = x509.BasicConstraints(False, None)
+ bc = x509.BasicConstraints(ca=False, path_length=None)
with pytest.raises(TypeError):
x509.Extension("notanoid", True, bc)
def test_critical_not_a_bool(self):
- bc = x509.BasicConstraints(False, None)
+ bc = x509.BasicConstraints(ca=False, path_length=None)
with pytest.raises(TypeError):
x509.Extension(x509.OID_BASIC_CONSTRAINTS, "notabool", bc)
def test_repr(self):
- bc = x509.BasicConstraints(False, None)
+ bc = x509.BasicConstraints(ca=False, path_length=None)
ext = x509.Extension(x509.OID_BASIC_CONSTRAINTS, True, bc)
assert repr(ext) == (
"<Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConst"
@@ -33,25 +33,25 @@ class TestExtension(object):
class TestBasicConstraints(object):
def test_ca_not_boolean(self):
with pytest.raises(TypeError):
- x509.BasicConstraints("notbool", None)
+ x509.BasicConstraints(ca="notbool", path_length=None)
def test_path_length_not_ca(self):
with pytest.raises(ValueError):
- x509.BasicConstraints(False, 0)
+ x509.BasicConstraints(ca=False, path_length=0)
def test_path_length_not_int(self):
with pytest.raises(TypeError):
- x509.BasicConstraints(True, 1.1)
+ x509.BasicConstraints(ca=True, path_length=1.1)
with pytest.raises(TypeError):
- x509.BasicConstraints(True, "notint")
+ x509.BasicConstraints(ca=True, path_length="notint")
def test_path_length_negative(self):
with pytest.raises(TypeError):
- x509.BasicConstraints(True, -1)
+ x509.BasicConstraints(ca=True, path_length=-1)
def test_repr(self):
- na = x509.BasicConstraints(True, None)
+ na = x509.BasicConstraints(ca=True, path_length=None)
assert repr(na) == (
"<BasicConstraints(ca=True, path_length=None)>"
)