1 from ctypescrypto import libcrypto
2 from ctypes import c_char_p, c_int, string_at
5 Provides interface to OpenSSL memory bios
6 use str() to get contents of writable bio
7 use bio member to pass to libcrypto function
9 def __init__(self,data=None):
10 """ If data is specified, creates read-only BIO. If data is
11 None, creates writable BIO
14 method=libcrypto.BIO_s_mem()
15 self.bio=libcrypto.BIO_new(method)
17 self.bio=libcrypto.BIO_new_mem_buf(c_char_p(data),len(data))q
19 libcrypto.BIO_free(self.bio)
23 l=BIO_get_mem_data(self.bio,byref(p))
25 #FIXME TODO - BIO should have stream-like interface
26 libcrypto.BIO_s_mem.restype=c_void_p
27 libcrypto.BIO_new.restype=c_void_p
28 libcrypto.BIO_new.argtypes=(c_void_p,)
29 libcrypto.BIO_get_mem_data.restype=c_long
30 libcrypto.BIO_get_mem_data.argtypes=(c_void_p,POINTER(c_char_p))