]> wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/x509.py
Add X509 to __all__. Add pem() method to X509
[oss/ctypescrypto.git] / ctypescrypto / x509.py
index dd4cba2b1c13b403359e98c4e1ca02b36158e7f0..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 
@@ -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 """
@@ -303,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 
@@ -538,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
@@ -568,3 +580,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,)