Coverage Report

Created: 2026-05-16 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-rs-1.16.2/src/ptr.rs
Line
Count
Source
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: Apache-2.0 OR ISC
3
4
use crate::aws_lc::{
5
    BN_free, CMAC_CTX_free, ECDSA_SIG_free, EC_GROUP_free, EC_KEY_free, EC_POINT_free,
6
    EVP_AEAD_CTX_free, EVP_CIPHER_CTX_free, EVP_PKEY_CTX_free, EVP_PKEY_free, OPENSSL_free,
7
    RSA_free, BIGNUM, CMAC_CTX, ECDSA_SIG, EC_GROUP, EC_KEY, EC_POINT, EVP_AEAD_CTX,
8
    EVP_CIPHER_CTX, EVP_PKEY, EVP_PKEY_CTX, RSA,
9
};
10
use std::marker::PhantomData;
11
12
pub(crate) type LcPtr<T> = ManagedPointer<*mut T>;
13
pub(crate) type DetachableLcPtr<T> = DetachablePointer<*mut T>;
14
15
#[derive(Debug)]
16
pub(crate) struct ManagedPointer<P: Pointer> {
17
    pointer: P,
18
}
19
20
impl<P: Pointer> ManagedPointer<P> {
21
    #[inline]
22
0
    pub fn new<T: IntoPointer<P>>(value: T) -> Result<Self, ()> {
23
0
        if let Some(pointer) = value.into_pointer() {
24
0
            Ok(Self { pointer })
25
        } else {
26
0
            Err(())
27
        }
28
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::cmac_ctx_st>>::new::<*mut aws_lc_sys::universal_crypto::cmac_ctx_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_point_st>>::new::<*mut aws_lc_sys::universal_crypto::ec_point_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::new::<*mut aws_lc_sys::universal_crypto::evp_pkey_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>>::new::<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st>>::new::<*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st>>::new::<*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st>>::new::<*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::new::<*mut aws_lc_sys::universal_crypto::bignum_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::new::<*mut aws_lc_sys::universal_crypto::ec_key_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut u8>>::new::<*mut u8>
29
30
0
    pub unsafe fn as_slice(&self, len: usize) -> &[P::T] {
31
0
        core::slice::from_raw_parts(self.pointer.as_const_ptr(), len)
32
0
    }
33
}
34
35
impl<P: Pointer> Drop for ManagedPointer<P> {
36
    #[inline]
37
0
    fn drop(&mut self) {
38
0
        self.pointer.free();
39
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::cmac_ctx_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_point_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::bignum_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_key_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut u8> as core::ops::drop::Drop>::drop
40
}
41
42
impl<'a, P: Pointer> From<&'a ManagedPointer<P>> for ConstPointer<'a, P::T> {
43
0
    fn from(ptr: &'a ManagedPointer<P>) -> ConstPointer<'a, P::T> {
44
0
        ConstPointer {
45
0
            ptr: ptr.pointer.as_const_ptr(),
46
0
            _lifetime: PhantomData,
47
0
        }
48
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_pkey_st> as core::convert::From<&aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>>::from
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::bignum_st> as core::convert::From<&aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::bignum_st>>>::from
49
}
50
51
impl<P: Pointer> ManagedPointer<P> {
52
    #[inline]
53
0
    pub fn as_const(&self) -> ConstPointer<'_, P::T> {
54
0
        self.into()
55
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::as_const
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::as_const
56
57
    #[inline]
58
0
    pub fn as_const_ptr(&self) -> *const P::T {
59
0
        self.pointer.as_const_ptr()
60
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::cmac_ctx_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_point_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut u8>>::as_const_ptr
61
62
0
    pub fn project_const_lifetime<'a, C>(
63
0
        &'a self,
64
0
        f: unsafe fn(&'a Self) -> *const C,
65
0
    ) -> Result<ConstPointer<'a, C>, ()> {
66
0
        let ptr = unsafe { f(self) };
67
0
        if ptr.is_null() {
68
0
            return Err(());
69
0
        }
70
0
        Ok(ConstPointer {
71
0
            ptr,
72
0
            _lifetime: PhantomData,
73
0
        })
74
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::bignum_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::ec_key_st>
75
76
    #[inline]
77
0
    pub fn as_mut_ptr(&mut self) -> *mut P::T {
78
0
        self.pointer.as_mut_ptr()
79
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::cmac_ctx_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_point_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ManagedPointer<*mut u8>>::as_mut_ptr
80
}
81
82
impl<P: Pointer> DetachablePointer<P> {
83
    #[inline]
84
0
    pub fn as_mut_ptr(&mut self) -> *mut P::T {
85
0
        self.pointer.as_mut().unwrap().as_mut_ptr()
86
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::rsa_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::as_mut_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut u8>>::as_mut_ptr
87
}
88
89
#[derive(Debug)]
90
#[allow(clippy::module_name_repetitions)]
91
pub(crate) struct DetachablePointer<P: Pointer> {
92
    pointer: Option<P>,
93
}
94
95
impl<P: Pointer> DetachablePointer<P> {
96
    #[inline]
97
0
    pub fn new<T: IntoPointer<P>>(value: T) -> Result<Self, ()> {
98
0
        if let Some(pointer) = value.into_pointer() {
99
0
            Ok(Self {
100
0
                pointer: Some(pointer),
101
0
            })
102
        } else {
103
0
            Err(())
104
        }
105
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::rsa_st>>::new::<*mut aws_lc_sys::universal_crypto::rsa_st>
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::new::<*mut aws_lc_sys::universal_crypto::bignum_st>
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::new::<*mut aws_lc_sys::universal_crypto::ec_key_st>
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut u8>>::new::<*mut u8>
106
107
    #[inline]
108
0
    pub fn detach(mut self) -> P {
109
0
        self.pointer.take().unwrap()
110
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::rsa_st>>::detach
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::detach
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::detach
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut u8>>::detach
111
}
112
113
impl<P: Pointer> From<DetachablePointer<P>> for ManagedPointer<P> {
114
    #[inline]
115
0
    fn from(mut dptr: DetachablePointer<P>) -> Self {
116
0
        match dptr.pointer.take() {
117
0
            Some(pointer) => ManagedPointer { pointer },
118
            None => {
119
                // Safety: pointer is only None when DetachableLcPtr is detached or dropped
120
0
                unreachable!()
121
            }
122
        }
123
0
    }
124
}
125
126
impl<P: Pointer> Drop for DetachablePointer<P> {
127
    #[inline]
128
0
    fn drop(&mut self) {
129
0
        if let Some(mut pointer) = self.pointer.take() {
130
0
            pointer.free();
131
0
        }
132
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::rsa_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::bignum_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut aws_lc_sys::universal_crypto::ec_key_st> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aws_lc_rs::ptr::DetachablePointer<*mut u8> as core::ops::drop::Drop>::drop
133
}
134
135
#[derive(Debug)]
136
pub(crate) struct ConstPointer<'a, T> {
137
    ptr: *const T,
138
    _lifetime: PhantomData<&'a T>,
139
}
140
141
impl<T> ConstPointer<'static, T> {
142
0
    pub unsafe fn new_static(ptr: *const T) -> Result<Self, ()> {
143
0
        if ptr.is_null() {
144
0
            return Err(());
145
0
        }
146
0
        Ok(ConstPointer {
147
0
            ptr,
148
0
            _lifetime: PhantomData,
149
0
        })
150
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_group_st>>::new_static
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_cipher_st>>::new_static
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::env_md_st>>::new_static
151
}
152
153
impl<T> ConstPointer<'_, T> {
154
0
    pub fn project_const_lifetime<'a, C>(
155
0
        &'a self,
156
0
        f: unsafe fn(&'a Self) -> *const C,
157
0
    ) -> Result<ConstPointer<'a, C>, ()> {
158
0
        let ptr = unsafe { f(self) };
159
0
        if ptr.is_null() {
160
0
            return Err(());
161
0
        }
162
0
        Ok(ConstPointer {
163
0
            ptr,
164
0
            _lifetime: PhantomData,
165
0
        })
166
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_pkey_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::rsa_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_pkey_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::ec_key_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::rsa_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::bignum_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_key_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::ec_group_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_key_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::ec_point_st>
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_key_st>>::project_const_lifetime::<aws_lc_sys::universal_crypto::bignum_st>
167
168
0
    pub fn as_const_ptr(&self) -> *const T {
169
0
        self.ptr
170
0
    }
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_group_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_point_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_pkey_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::evp_cipher_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::rsa_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::bignum_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::ec_key_st>>::as_const_ptr
Unexecuted instantiation: <aws_lc_rs::ptr::ConstPointer<aws_lc_sys::universal_crypto::env_md_st>>::as_const_ptr
171
}
172
173
pub(crate) trait Pointer {
174
    type T;
175
176
    fn free(&mut self);
177
    fn as_const_ptr(&self) -> *const Self::T;
178
    fn as_mut_ptr(&mut self) -> *mut Self::T;
179
}
180
181
pub(crate) trait IntoPointer<P> {
182
    fn into_pointer(self) -> Option<P>;
183
}
184
185
impl<T> IntoPointer<*mut T> for *mut T {
186
    #[inline]
187
0
    fn into_pointer(self) -> Option<*mut T> {
188
0
        if self.is_null() {
189
0
            None
190
        } else {
191
0
            Some(self)
192
        }
193
0
    }
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::cmac_ctx_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::cmac_ctx_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_point_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::ec_point_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ecdsa_sig_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::ecdsa_sig_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::rsa_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::rsa_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::bignum_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::bignum_st>>::into_pointer
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_key_st as aws_lc_rs::ptr::IntoPointer<*mut aws_lc_sys::universal_crypto::ec_key_st>>::into_pointer
Unexecuted instantiation: <*mut u8 as aws_lc_rs::ptr::IntoPointer<*mut u8>>::into_pointer
194
}
195
196
macro_rules! create_pointer {
197
    ($ty:ty, $free:path) => {
198
        impl Pointer for *mut $ty {
199
            type T = $ty;
200
201
            #[inline]
202
0
            fn free(&mut self) {
203
0
                unsafe {
204
0
                    let ptr = *self;
205
0
                    $free(ptr.cast());
206
0
                }
207
0
            }
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_point_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_key_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ecdsa_sig_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::bignum_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::rsa_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::cmac_ctx_st as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut u8 as aws_lc_rs::ptr::Pointer>::free
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_group_st as aws_lc_rs::ptr::Pointer>::free
208
209
            #[inline]
210
0
            fn as_const_ptr(&self) -> *const Self::T {
211
0
                self.cast()
212
0
            }
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_point_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ecdsa_sig_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::bignum_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::cmac_ctx_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut u8 as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_group_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_key_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::rsa_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st as aws_lc_rs::ptr::Pointer>::as_const_ptr
213
214
            #[inline]
215
0
            fn as_mut_ptr(&mut self) -> *mut Self::T {
216
0
                *self
217
0
            }
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_point_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_key_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ecdsa_sig_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::bignum_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_pkey_ctx_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::rsa_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_aead_ctx_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::evp_cipher_ctx_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::cmac_ctx_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut u8 as aws_lc_rs::ptr::Pointer>::as_mut_ptr
Unexecuted instantiation: <*mut aws_lc_sys::universal_crypto::ec_group_st as aws_lc_rs::ptr::Pointer>::as_mut_ptr
218
        }
219
    };
220
}
221
222
// `OPENSSL_free` and the other `XXX_free` functions perform a zeroization of the memory when it's
223
// freed. This is different than functions of the same name in OpenSSL which generally do not zero
224
// memory.
225
create_pointer!(u8, OPENSSL_free);
226
create_pointer!(EC_GROUP, EC_GROUP_free);
227
create_pointer!(EC_POINT, EC_POINT_free);
228
create_pointer!(EC_KEY, EC_KEY_free);
229
create_pointer!(ECDSA_SIG, ECDSA_SIG_free);
230
create_pointer!(BIGNUM, BN_free);
231
create_pointer!(EVP_PKEY, EVP_PKEY_free);
232
create_pointer!(EVP_PKEY_CTX, EVP_PKEY_CTX_free);
233
create_pointer!(RSA, RSA_free);
234
create_pointer!(EVP_AEAD_CTX, EVP_AEAD_CTX_free);
235
create_pointer!(EVP_CIPHER_CTX, EVP_CIPHER_CTX_free);
236
create_pointer!(CMAC_CTX, CMAC_CTX_free);
237
238
#[cfg(test)]
239
mod tests {
240
    use crate::aws_lc::BIGNUM;
241
    use crate::ptr::{DetachablePointer, ManagedPointer};
242
243
    #[test]
244
    fn test_debug() {
245
        let num = 100u64;
246
        let detachable_ptr: DetachablePointer<*mut BIGNUM> =
247
            DetachablePointer::try_from(num).unwrap();
248
        let debug = format!("{detachable_ptr:?}");
249
        assert!(debug.contains("DetachablePointer { pointer: Some("));
250
251
        let lc_ptr = ManagedPointer::new(detachable_ptr.detach()).unwrap();
252
        let debug = format!("{lc_ptr:?}");
253
        assert!(debug.contains("ManagedPointer { pointer:"));
254
    }
255
}