Skip to content

Commit

Permalink
Merge pull request #2294 from bjmc/add_name_to_oids
Browse files Browse the repository at this point in the history
Adds name property to ObjectIdentifier
  • Loading branch information
reaperhulk committed Sep 8, 2015
2 parents 786ded6 + ae45413 commit 948ba5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cryptography/x509/oid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ def __ne__(self, other):
def __repr__(self):
return "<ObjectIdentifier(oid={0}, name={1})>".format(
self.dotted_string,
_OID_NAMES.get(self, "Unknown OID")
self._name
)

def __hash__(self):
return hash(self.dotted_string)

@property
def _name(self):
return _OID_NAMES.get(self, "Unknown OID")

dotted_string = utils.read_only_property("_dotted_string")


Expand Down
6 changes: 6 additions & 0 deletions tests/test_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,12 @@ def test_repr(self):
oid = x509.ObjectIdentifier("oid1")
assert repr(oid) == "<ObjectIdentifier(oid=oid1, name=Unknown OID)>"

def test_name_property(self):
oid = x509.ObjectIdentifier("2.5.4.3")
assert oid._name == 'commonName'
oid = x509.ObjectIdentifier("oid1")
assert oid._name == 'Unknown OID'


class TestName(object):
def test_eq(self):
Expand Down

0 comments on commit 948ba5d

Please sign in to comment.