From a5c6e9a89242bb42dbc98f29681d2f74aec12b02 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 23 Mar 2015 19:23:43 -0500 Subject: use kwargs for BasicConstraints creation Also check path_length using integer_types --- src/cryptography/x509.py | 7 +++++-- tests/test_x509_ext.py | 18 +++++++++--------- 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) == ( "" ) -- cgit v1.2.3