1 /* This is a simple example of using the base64 BIO to a memory BIO and then
5 #include <openssl/bio.h>
6 #include <openssl/evp.h>
11 BIO
*mbio
,*b64bio
,*bio
;
15 mbio
=BIO_new(BIO_s_mem());
16 b64bio
=BIO_new(BIO_f_base64());
18 bio
=BIO_push(b64bio
,mbio
);
19 /* We now have bio pointing at b64->mem, the base64 bio encodes on
20 * write and decodes on read */
24 i
=fread(buf
,1,512,stdin
);
28 /* We need to 'flush' things to push out the encoding of the
29 * last few bytes. There is special encoding if it is not a
34 printf("We have %d bytes available\n",BIO_pending(mbio
));
36 /* We will now get a pointer to the data and the number of elements. */
37 /* hmm... this one was not defined by a macro in bio.h, it will be for
38 * 0.9.1. The other option is too just read from the memory bio.
40 i
=(int)BIO_ctrl(mbio
,BIO_CTRL_INFO
,0,(char *)&p
);
43 fwrite("---\n",1,4,stdout
);
45 fwrite("---\n",1,4,stdout
);
47 /* This call will walk the chain freeing all the BIOs */