]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/bio.py
Python 3 support for modules pbkdf2 pkey ec x509
[oss/ctypescrypto.git] / ctypescrypto / bio.py
index 75d5f6a608ad9294c5b820d065301f5ec4e34f7d..0c80263b08fb500f2e46a9ca13321127ff7d2dd2 100644 (file)
@@ -1,7 +1,7 @@
 """
 Interface to OpenSSL BIO library
 """
 """
 Interface to OpenSSL BIO library
 """
-from ctypescrypto import libcrypto,pyver, inttype
+from ctypescrypto import libcrypto,pyver, inttype, chartype
 from ctypes import c_char_p, c_void_p, c_int, string_at, c_long
 from ctypes import POINTER, byref, create_string_buffer
 class Membio(object):
 from ctypes import c_char_p, c_void_p, c_int, string_at, c_long
 from ctypes import POINTER, byref, create_string_buffer
 class Membio(object):
@@ -9,19 +9,30 @@ class Membio(object):
     Provides interface to OpenSSL memory bios
     use str() or unicode() to get contents of writable bio
     use bio member to pass to libcrypto function
     Provides interface to OpenSSL memory bios
     use str() or unicode() to get contents of writable bio
     use bio member to pass to libcrypto function
+    
     """
     """
-    def __init__(self, data=None):
+    def __init__(self, data=None, clone=False):
         """
         """
-        If data is specified, creates read-only BIO. If data is
+        If data is specified, creates read-only BIO. 
+        If clone is True, makes copy of data in the instance member
+        If data is
         None, creates writable BIO, contents of which can be retrieved
         by str() or unicode()
         None, creates writable BIO, contents of which can be retrieved
         by str() or unicode()
+        
         """
         if data is None:
             method = libcrypto.BIO_s_mem()
             self.bio = libcrypto.BIO_new(method)
         else:
         """
         if data is None:
             method = libcrypto.BIO_s_mem()
             self.bio = libcrypto.BIO_new(method)
         else:
-            self.bio = libcrypto.BIO_new_mem_buf(c_char_p(data), len(data))
-
+            if isinstance(data, chartype):
+                data = data.encode("utf-8")
+                clone = True
+            if clone :
+                self.data = data
+                self.bio = libcrypto.BIO_new_mem_buf(c_char_p(self.data), len(data))
+            else:
+                self.bio = libcrypto.BIO_new_mem_buf(c_char_p(data), len(data))
+                
     def __del__(self):
         """
         Cleans up memory used by bio
     def __del__(self):
         """
         Cleans up memory used by bio