]> wagner.pp.ru Git - oss/ctypescrypto.git/commitdiff
Add X509 to __all__. Add pem() method to X509
authorVictor Wagner <vitus@wagner.pp.ru>
Sun, 15 Feb 2015 11:36:30 +0000 (14:36 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Sun, 15 Feb 2015 11:36:30 +0000 (14:36 +0300)
ctypescrypto/x509.py
setup.py
tests/testx509.py

index e2ddea88f508f336f822f43ea9ad5c640e6751e7..bd81fdd01c207f04b024f5d75d3b673d97a9b628 100644 (file)
@@ -36,7 +36,7 @@ except ImportError:
 
        utc=UTC()
 
-__all__ = ['X509Error','X509Name','X509Store','StackOfX509']
+__all__ = ['X509','X509Error','X509Name','X509Store','StackOfX509']
 
 class _validity(Structure):
        """ ctypes representation of X509_VAL structure 
@@ -305,6 +305,12 @@ class X509(object):
        def pubkey(self):
                """EVP PKEy object of certificate public key"""
                return PKey(ptr=libcrypto.X509_get_pubkey(self.cert,False))
+       def pem(self):
+               """ Returns PEM represntation of the certificate """
+               b=Membio()
+               if libcrypto.PEM_write_bio_X509(b.bio,self.cert)==0:
+                       raise X509Error("error serializing certificate")
+               return str(b)
        def verify(self,store=None,chain=[],key=None):  
                """ 
                Verify self. Supports verification on both X509 store object 
@@ -540,6 +546,10 @@ class StackOfX509(object):
                libcrypto.sk_push(self.ptr,libcrypto.X509_dup(value.cert))
 libcrypto.i2a_ASN1_INTEGER.argtypes=(c_void_p,c_void_p)
 libcrypto.ASN1_STRING_print_ex.argtypes=(c_void_p,c_void_p,c_long)
+libcrypto.PEM_read_bio_X509.restype=c_void_p
+libcrypto.PEM_read_bio_X509.argtypes=(c_void_p,POINTER(c_void_p),c_void_p,c_void_p)
+libcrypto.PEM_write_bio_X509.restype=c_int
+libcrypto.PEM_write_bio_X509.argtypes=(c_void_p,c_void_p)
 libcrypto.ASN1_TIME_print.argtypes=(c_void_p,c_void_p)
 libcrypto.ASN1_INTEGER_get.argtypes=(c_void_p,)
 libcrypto.ASN1_INTEGER_get.restype=c_long
index 48494288f3bfaf7e06d1e7fb03d55399718eb32c..634f049c5a896fcdd98745289938be52973e0f11 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ class MyTests(distutils.cmd.Command):
 
 setup(
        name="ctypescrypto",
-       version="0.2.4",
+       version="0.2.6",
        description="CTypes-based interface for some OpenSSL libcrypto features",
        author="Victor Wagner",
        author_email="vitus@wagner.pp.ru",
index 060d8117111e96f80fc1e57940b86ab0ddadf66c..50b3b6a7f5e05928918263bd8f52d6156e77a188 100644 (file)
@@ -115,6 +115,9 @@ zVMSW4SOwg/H7ZMZ2cn6j1g0djIvruFQFGHUqFijyDATI+/GJYw2jxyA
                c=X509(self.cert1)
                p=c.pubkey
                self.assertEqual(p.exportpub(),self.pubkey1)
+       def test_pem(self):
+               c=X509(self.cert1)
+               self.assertEqual(c.pem(),self.cert1)
        def test_subject(self):
                c=X509(self.cert1)
                self.assertEqual(unicode(c.subject),u'C=RU,ST=Москва,L=Москва,O=Частное лицо,CN=Виктор Вагнер')