Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/x509.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ General Name Classes

.. attribute:: value

:type: :class:`~ipaddress.IPv4Address` or
:class:`~ipaddress.IPv6Address`.
:type: :class:`~ipaddress.IPv4Address`,
:class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
or :class:`~ipaddress.IPv6Network`.

.. class:: RegisteredID

Expand Down
13 changes: 10 additions & 3 deletions src/cryptography/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,18 @@ def __ne__(self, other):
class IPAddress(object):
def __init__(self, value):
if not isinstance(
value, (ipaddress.IPv4Address, ipaddress.IPv6Address)
value,
(
ipaddress.IPv4Address,
ipaddress.IPv6Address,
ipaddress.IPv4Network,
ipaddress.IPv6Network
)
):
raise TypeError(
"value must be an instance of ipaddress.IPv4Address or "
"ipaddress.IPv6Address"
"value must be an instance of ipaddress.IPv4Address, "
"ipaddress.IPv6Address, ipaddress.IPv4Network, or "
"ipaddress.IPv6Network"
)

self._value = value
Expand Down
6 changes: 6 additions & 0 deletions tests/test_x509_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,12 @@ def test_repr(self):
gn2 = x509.IPAddress(ipaddress.IPv6Address(u"ff::"))
assert repr(gn2) == "<IPAddress(value=ff::)>"

gn3 = x509.IPAddress(ipaddress.IPv4Network(u"192.168.0.0/24"))
assert repr(gn3) == "<IPAddress(value=192.168.0.0/24)>"

gn4 = x509.IPAddress(ipaddress.IPv6Network(u"ff::/96"))
assert repr(gn4) == "<IPAddress(value=ff::/96)>"

def test_eq(self):
gn = x509.IPAddress(ipaddress.IPv4Address(u"127.0.0.1"))
gn2 = x509.IPAddress(ipaddress.IPv4Address(u"127.0.0.1"))
Expand Down