Skip to content

Commit

Permalink
Merge pull request #2594 from reaperhulk/hash-bc
Browse files Browse the repository at this point in the history
implement hash on basicconstraints
  • Loading branch information
alex committed Dec 27, 2015
2 parents b04b67e + b39af8d commit b25888d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cryptography/x509/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def __hash__(self):
return hash((self.ca, self.path_length))


@utils.register_interface(ExtensionType)
class CRLDistributionPoints(object):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_x509_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,13 @@ def test_repr(self):
"<BasicConstraints(ca=True, path_length=None)>"
)

def test_hash(self):
na = x509.BasicConstraints(ca=True, path_length=None)
na2 = x509.BasicConstraints(ca=True, path_length=None)
na3 = x509.BasicConstraints(ca=True, path_length=0)
assert hash(na) == hash(na2)
assert hash(na) != hash(na3)

def test_eq(self):
na = x509.BasicConstraints(ca=True, path_length=None)
na2 = x509.BasicConstraints(ca=True, path_length=None)
Expand Down

0 comments on commit b25888d

Please sign in to comment.