From 85a6cf49ee43a6948d7af79fdc9521360ae4c405 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Wed, 4 Feb 2015 16:11:31 +0300 Subject: [PATCH] Added X509Name.__hash__ --- MANIFEST.in | 4 ++++ ctypescrypto/x509.py | 4 ++++ tests/testx509.py | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 16b52e4..62a0e2c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,5 @@ include tests/*.py +include LICENSE +include README.md +include MANIFEST +include MANIFEST.in diff --git a/ctypescrypto/x509.py b/ctypescrypto/x509.py index dd4cba2..e2ddea8 100644 --- a/ctypescrypto/x509.py +++ b/ctypescrypto/x509.py @@ -177,6 +177,8 @@ class X509Name(object): raise ValueError("Attempt to modify constant X509 object") else: raise NotImplementedError + def __hash__(self): + return libcrypto.X509_NAME_hash(self.ptr) class _x509_ext(Structure): """ Represens C structure X509_EXTENSION """ @@ -568,3 +570,5 @@ libcrypto.sk_value.restype=c_void_p libcrypto.X509_dup.restype=c_void_p libcrypto.sk_new_null.restype=c_void_p libcrypto.X509_dup.argtypes=(c_void_p,) +libcrypto.X509_NAME_hash.restype=c_long +libcrypto.X509_NAME_hash.argtypes=(c_void_p,) diff --git a/tests/testx509.py b/tests/testx509.py index 060cc09..060d811 100644 --- a/tests/testx509.py +++ b/tests/testx509.py @@ -158,6 +158,12 @@ zVMSW4SOwg/H7ZMZ2cn6j1g0djIvruFQFGHUqFijyDATI+/GJYw2jxyA def test_notAfter(self): c=X509(self.cert1) self.assertEqual(c.endDate,datetime.datetime(2024,10,23,19,7,17,0,utc)) + def test_subjectHash(self): + c=X509(self.cert1) + self.assertEqual(hash(c.subject),0x1f3ed722) + def test_issuerHash(self): + c=X509(self.cert1) + self.assertEqual(hash(c.issuer),0x7d3ea8c3) def test_namecomp(self): c=X509(self.cert1) ca=X509(self.ca_cert) -- 2.39.5