26 #include <openssl/err.h>
31 static const int ERR_BUF_SIZE = 256;
36 static int bwrite(BIO *bio,
const char *buf,
int len);
37 static int bread(BIO *bio,
char *buf,
int len);
40 static long ctrl(BIO *bio,
int cmd,
long num,
void *ptr);
41 static int create(BIO *bio);
46 static BIO_METHOD iostream_method =
64 _bio = BIO_new(&iostream_method);
67 char err_buf[ERR_BUF_SIZE];
68 ERR_error_string_n(ERR_get_error(), err_buf, ERR_BUF_SIZE);
69 err_buf[ERR_BUF_SIZE - 1] =
'\0';
82 static int create(BIO *bio)
102 static long ctrl(BIO *bio,
int cmd,
long num,
void *)
105 iostream *stream =
reinterpret_cast<iostream*
>(bio->ptr);
126 }
catch(ios_base::failure &ex){
148 static int bread(BIO *bio,
char *buf,
int len)
150 iostream *stream =
reinterpret_cast<iostream*
>(bio->ptr);
151 int num_bytes = bio->num;
155 num_bytes =
static_cast<int>( stream->read(buf, 1).readsome(buf+1, len-1) + 1 );
156 }
catch(ios_base::failure &ex){
168 static int bwrite(BIO *bio,
const char *buf,
int len)
173 iostream *stream =
reinterpret_cast<iostream*
>(bio->ptr);
177 stream->write(buf, len);
178 }
catch(ios_base::failure &ex){
192 }
catch(ios_base::failure &ex){