aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/x509.rst1
-rw-r--r--src/cryptography/x509.py8
-rw-r--r--tests/test_x509_ext.py9
3 files changed, 12 insertions, 6 deletions
diff --git a/docs/x509.rst b/docs/x509.rst
index 7ee4516d..2dac33bc 100644
--- a/docs/x509.rst
+++ b/docs/x509.rst
@@ -981,6 +981,7 @@ X.509 Extensions
:ref:`general name classes <general_name_classes>`.
:returns: A list of values extracted from the matched general names.
+ The type of the returned values depends on the :class:`GeneralName`.
.. doctest::
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 48949b61..c9d0c260 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -1090,7 +1090,13 @@ class GeneralNames(object):
return len(self._general_names)
def get_values_for_type(self, type):
- return [i.value for i in self if isinstance(i, type)]
+ # Return the value of each GeneralName, except for OtherName instances
+ # which we return directly because it has two important properties not
+ # just one value.
+ objs = (i for i in self if isinstance(i, type))
+ if type != OtherName:
+ objs = (i.value for i in objs)
+ return list(objs)
def __repr__(self):
return "<GeneralNames({0})>".format(self._general_names)
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index e6ee7d66..993802b8 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -1642,14 +1642,13 @@ class TestRSASubjectAlternativeNameExtension(object):
assert ext is not None
assert ext.critical is False
+ expected = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"),
+ b'\x16\x0bHello World')
assert len(ext.value) == 1
- assert list(ext.value)[0] == \
- x509.OtherName(
- x509.ObjectIdentifier("1.2.3.4"),
- b'\x16\x0bHello World')
+ assert list(ext.value)[0] == expected
othernames = ext.value.get_values_for_type(x509.OtherName)
- assert othernames == [b'\x16\x0bHello World']
+ assert othernames == [expected]
@pytest.mark.requires_backend_interface(interface=RSABackend)