3 use std
::marker
::PhantomData
;
8 use crate::error
::ErrorStack
;
10 pub struct MemBioSlice
<'a
>(*mut ffi
::BIO
, PhantomData
<&'a
[u8]>);
12 impl<'a
> Drop
for MemBioSlice
<'a
> {
15 ffi
::BIO_free_all(self.0);
20 impl<'a
> MemBioSlice
<'a
> {
21 pub fn new(buf
: &'a
[u8]) -> Result
<MemBioSlice
<'a
>, ErrorStack
> {
24 assert
!(buf
.len() <= c_int
::max_value() as usize);
26 cvt_p(BIO_new_mem_buf(
27 buf
.as_ptr() as *const _
,
32 Ok(MemBioSlice(bio
, PhantomData
))
35 pub fn as_ptr(&self) -> *mut ffi
::BIO
{
40 pub struct MemBio(*mut ffi
::BIO
);
42 impl Drop
for MemBio
{
45 ffi
::BIO_free_all(self.0);
51 pub fn new() -> Result
<MemBio
, ErrorStack
> {
54 let bio
= unsafe { cvt_p(ffi::BIO_new(ffi::BIO_s_mem()))? }
;
58 pub fn as_ptr(&self) -> *mut ffi
::BIO
{
62 pub fn get_buf(&self) -> &[u8] {
64 let mut ptr
= ptr
::null_mut();
65 let len
= ffi
::BIO_get_mem_data(self.0, &mut ptr
);
66 slice
::from_raw_parts(ptr
as *const _
as *const _
, len
as usize)
70 #[cfg(not(boringssl))]
71 pub unsafe fn from_ptr(bio
: *mut ffi
::BIO
) -> MemBio
{
78 use ffi
::BIO_new_mem_buf
;
81 unsafe fn BIO_new_mem_buf(buf
: *const ::libc
::c_void
, len
: ::libc
::c_int
) -> *mut ffi
::BIO
{
82 ffi
::BIO_new_mem_buf(buf
as *mut _
, len
)