from ctypescrypto import libcrypto
from ctypes import c_char_p, c_void_p, c_int, string_at, c_long,POINTER,byref, create_string_buffer
class Membio:
"""
Provides interface to OpenSSL memory bios
from ctypescrypto import libcrypto
from ctypes import c_char_p, c_void_p, c_int, string_at, c_long,POINTER,byref, create_string_buffer
class Membio:
"""
Provides interface to OpenSSL memory bios
use bio member to pass to libcrypto function
"""
def __init__(self,data=None):
""" If data is specified, creates read-only BIO. If data is
use bio member to pass to libcrypto function
"""
def __init__(self,data=None):
""" If data is specified, creates read-only BIO. If data is
p=c_char_p(None)
l=libcrypto.BIO_ctrl(self.bio,3,0,byref(p))
return string_at(p,l)
p=c_char_p(None)
l=libcrypto.BIO_ctrl(self.bio,3,0,byref(p))
return string_at(p,l)
r=libcrypto.BIO_write(self.bio,data,len(data))
if r==-2:
raise NotImplementedError("Function not supported by this BIO")
if r<len(data):
raise IOError("Not all data were successfully written")
r=libcrypto.BIO_write(self.bio,data,len(data))
if r==-2:
raise NotImplementedError("Function not supported by this BIO")
if r<len(data):
raise IOError("Not all data were successfully written")
-
-#FIXME TODO - BIO should have stream-like interface
+ def reset(self):
+ """
+ Resets the read-only bio to start and discards all data from writable bio
+ """
+ libcrypto.BIO_ctrl(self.bio,1,0,None)
libcrypto.BIO_s_mem.restype=c_void_p
libcrypto.BIO_new.restype=c_void_p
libcrypto.BIO_new.argtypes=(c_void_p,)
libcrypto.BIO_s_mem.restype=c_void_p
libcrypto.BIO_new.restype=c_void_p
libcrypto.BIO_new.argtypes=(c_void_p,)
libcrypto.BIO_free.argtypes=(c_void_p,)
libcrypto.BIO_new_mem_buf.restype=c_void_p
libcrypto.BIO_new_mem_buf.argtypes=(c_char_p,c_int)
libcrypto.BIO_free.argtypes=(c_void_p,)
libcrypto.BIO_new_mem_buf.restype=c_void_p
libcrypto.BIO_new_mem_buf.argtypes=(c_char_p,c_int)