'Reads a memory BIO. This only works on memory BIOs.'

def _read_mem_bio(self, bio):

    buf = self._ffi.new('char    **')
    buf_len = self._lib.BIO_get_mem_data(bio, buf)
    self.openssl_assert((buf_len > 0))
    self.openssl_assert((buf[0] != self._ffi.NULL))
    bio_data = self._ffi.buffer(buf[0], buf_len)[:]
    return bio_data
