X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fbio.py;fp=ctypescrypto%2Fbio.py;h=1263ce64dc12a305924a0ce8dedb6a309b1d0a73;hb=1ff9b1899959673512927b6afa317855908b7073;hp=0000000000000000000000000000000000000000;hpb=7b229d0dba6fc42eddf3c359c3d9510330a1eeaf;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/bio.py b/ctypescrypto/bio.py new file mode 100644 index 0000000..1263ce6 --- /dev/null +++ b/ctypescrypto/bio.py @@ -0,0 +1,30 @@ +from ctypescrypto import libcrypto +from ctypes import c_char_p, c_int, string_at +class Membio: + """ + Provides interface to OpenSSL memory bios + use str() to get contents of writable bio + use bio member to pass to libcrypto function + """ + def __init__(self,data=None): + """ If data is specified, creates read-only BIO. If data is + None, creates writable BIO + """ + 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))q + def __del__(self): + libcrypto.BIO_free(self.bio) + del(self.bio) + def __str__(self): + p=c_char_p(None) + l=BIO_get_mem_data(self.bio,byref(p)) + return string_at(p,l) +#FIXME TODO - BIO should have stream-like interface +libcrypto.BIO_s_mem.restype=c_void_p +libcrypto.BIO_new.restype=c_void_p +libcrypto.BIO_new.argtypes=(c_void_p,) +libcrypto.BIO_get_mem_data.restype=c_long +libcrypto.BIO_get_mem_data.argtypes=(c_void_p,POINTER(c_char_p))