diff options
-rw-r--r-- | docs/x509.rst | 31 | ||||
-rw-r--r-- | src/cryptography/x509.py | 30 | ||||
-rw-r--r-- | tests/test_x509_ext.py | 69 |
3 files changed, 37 insertions, 93 deletions
diff --git a/docs/x509.rst b/docs/x509.rst index 20929768..48cb0730 100644 --- a/docs/x509.rst +++ b/docs/x509.rst @@ -918,30 +918,7 @@ These classes may be present within a :class:`CertificatePolicies` instance. :type: list - A list of :class:`PolicyQualifierInfo` objects. - -.. class:: PolicyQualifierInfo - - .. versionadded:: 0.9 - - .. attribute:: policy_qualifier_id - - :type: :class:`ObjectIdentifier` - - This attribute can have two possible values: :data:`OID_CPS_QUALIFIER` - or :data:`OID_CPS_USER_NOTICE`. If it is :data:`OID_CPS_QUALIFIER` then - ``qualifier`` will be :term:`text` and should contain a pointer to - a certification practice statement (CPS) published by the CA. This - text should be in the form of a URI. If it is - :data:`OID_CPS_USER_NOTICE` then ``qualifier`` will be - :class:`UserNotice`. - - .. attribute:: qualifier - - :type: :term:`text` or :class:`UserNotice` - - The type of this attribute is determined by checking the - ``policy_qualifier_id``. + A list consisting of :term:`text` and/or :class:`UserNotice` objects. .. class:: UserNotice @@ -1196,13 +1173,11 @@ Policy Qualifier OIDs .. data:: OID_CPS_QUALIFIER - Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``. Used as an - identifier in :class:`PolicyQualifierInfo` objects. + Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``. .. data:: OID_CPS_USER_NOTICE - Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``. Used as an - identifier in :class:`PolicyQualifierInfo` objects. + Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``. .. _extension_oids: diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index eb7731fc..b559ae03 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -489,11 +489,13 @@ class PolicyInformation(object): self._policy_identifier = policy_identifier if policy_qualifiers and not all( - isinstance(x, PolicyQualifierInfo) for x in policy_qualifiers + isinstance( + x, (six.text_type, UserNotice) + ) for x in policy_qualifiers ): raise TypeError( - "policy_qualifiers must be a list of PolicyQualifierInfo " - "objects or None" + "policy_qualifiers must be a list of strings and/or UserNotice" + " objects or None" ) self._policy_qualifiers = policy_qualifiers @@ -508,28 +510,6 @@ class PolicyInformation(object): policy_qualifiers = utils.read_only_property("_policy_qualifiers") -class PolicyQualifierInfo(object): - def __init__(self, qualifier): - if not isinstance(qualifier, (six.string_types, UserNotice)): - raise ValueError("qualifier must be string or UserNotice") - - if isinstance(qualifier, six.string_types): - self._policy_qualifier_id = OID_CPS_QUALIFIER - else: - self._policy_qualifier_id = OID_CPS_USER_NOTICE - - self._qualifier = qualifier - - def __repr__(self): - return ( - "<PolicyQualifierInfo(policy_qualifier_id={0.policy_qualifier_id}" - ", qualifier={0.qualifier})>".format(self) - ) - - policy_qualifier_id = utils.read_only_property("_policy_qualifier_id") - qualifier = utils.read_only_property("_qualifier") - - class UserNotice(object): def __init__(self, notice_reference, explicit_text): if notice_reference and not isinstance( diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index c6303432..10afa1b7 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -75,29 +75,6 @@ class TestUserNotice(object): ) -class TestPolicyQualifierInfo(object): - def test_invalid_qualifier(self): - with pytest.raises(ValueError): - x509.PolicyQualifierInfo(None) - - def test_string_qualifier(self): - pqi = x509.PolicyQualifierInfo("1.2.3") - assert pqi.policy_qualifier_id == x509.OID_CPS_QUALIFIER - assert pqi.qualifier == "1.2.3" - - def test_user_notice_qualifier(self): - pqi = x509.PolicyQualifierInfo(x509.UserNotice(None, "text")) - assert pqi.policy_qualifier_id == x509.OID_CPS_USER_NOTICE - assert isinstance(pqi.qualifier, x509.UserNotice) - - def test_repr(self): - pqi = x509.PolicyQualifierInfo("1.2.3.4") - assert repr(pqi) == ( - "<PolicyQualifierInfo(policy_qualifier_id=<ObjectIdentifier(oid=1." - "3.6.1.5.5.7.2.1, name=id-qt-cps)>, qualifier=1.2.3.4)>" - ) - - class TestPolicyInformation(object): def test_invalid_policy_identifier(self): with pytest.raises(TypeError): @@ -109,7 +86,7 @@ class TestPolicyInformation(object): assert pi.policy_qualifiers is None def test_policy_qualifiers(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) assert pi.policy_identifier == x509.ObjectIdentifier("1.2.3") assert pi.policy_qualifiers == pq @@ -119,25 +96,31 @@ class TestPolicyInformation(object): x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), [1, 2]) def test_repr(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string", x509.UserNotice(None, "hi")] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) - assert repr(pi) == ( - "<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=1.2.3," - " name=Unknown OID)>, policy_qualifiers=[<PolicyQualifierInfo(poli" - "cy_qualifier_id=<ObjectIdentifier(oid=1.3.6.1.5.5.7.2.1, name=id-" - "qt-cps)>, qualifier=string)>])>" - ) + if six.PY3: + assert repr(pi) == ( + "<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=1." + "2.3, name=Unknown OID)>, policy_qualifiers=['string', <UserNo" + "tice(notice_reference=None, explicit_text=hi)>])>" + ) + else: + assert repr(pi) == ( + "<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=1." + "2.3, name=Unknown OID)>, policy_qualifiers=[u'string', <UserN" + "otice(notice_reference=None, explicit_text=hi)>])>" + ) class TestCertificatePolicies(object): def test_invalid_policies(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) with pytest.raises(TypeError): x509.CertificatePolicies([1, pi]) def test_iter_len(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) cp = x509.CertificatePolicies([pi]) assert len(cp) == 1 @@ -145,15 +128,21 @@ class TestCertificatePolicies(object): assert policyinfo == pi def test_repr(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) cp = x509.CertificatePolicies([pi]) - assert repr(cp) == ( - "<CertificatePolicies([<PolicyInformation(policy_identifier=<Objec" - "tIdentifier(oid=1.2.3, name=Unknown OID)>, policy_qualifiers=[<Po" - "licyQualifierInfo(policy_qualifier_id=<ObjectIdentifier(oid=1.3.6" - ".1.5.5.7.2.1, name=id-qt-cps)>, qualifier=string)>])>])>" - ) + if six.PY3: + assert repr(cp) == ( + "<CertificatePolicies([<PolicyInformation(policy_identifier=<O" + "bjectIdentifier(oid=1.2.3, name=Unknown OID)>, policy_qualifi" + "ers=['string'])>])>" + ) + else: + assert repr(cp) == ( + "<CertificatePolicies([<PolicyInformation(policy_identifier=<O" + "bjectIdentifier(oid=1.2.3, name=Unknown OID)>, policy_qualifi" + "ers=[u'string'])>])>" + ) class TestKeyUsage(object): |