Coverage Report

Created: 2025-12-12 07:03

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