aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/types.rs
blob: 16829ea4b2b0c23cd54058160712b2573ace9460 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::marker::PhantomData;

use opaque::Opaque;

pub unsafe trait OpenSslType {
    type CType;

    unsafe fn from_ptr(ptr: *mut Self::CType) -> Self;

    fn as_ptr(&self) -> *mut Self::CType;
}

pub struct Ref<T>(Opaque, PhantomData<T>);

impl<T: OpenSslType> Ref<T> {
    pub unsafe fn from_ptr<'a>(ptr: *mut T::CType) -> &'a Ref<T> {
        &*(ptr as *mut _)
    }

    pub unsafe fn from_ptr_mut<'a>(ptr: *mut T::CType) -> &'a mut Ref<T> {
        &mut *(ptr as *mut _)
    }

    pub fn as_ptr(&self) -> *mut T::CType {
        self as *const _ as *mut _
    }
}