openssl_kdf/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// See also the LICENSE file in the root of the crate for additional copyright
5// information.
6
7//! Crate wrapping the openssl 3.0 KDF APIs.
8//!
9//! This crate can be removed once these capabilities are added to the upstream
10//! openssl crate. They are included here instead of in a fork of the openssl
11//! crate to avoid unnecessary forking.
12
13// Currently this crate is only consumed by other cfg(unix) crates.
14#![cfg(unix)]
15#![expect(missing_docs)]
16// UNSAFETY: Calls into openssl.
17#![expect(unsafe_code)]
18
19pub mod kdf;
20pub mod params;
21mod sys;
22
23use libc::c_int;
24use openssl::error::ErrorStack;
25
26fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
27 if r.is_null() {
28 Err(ErrorStack::get())
29 } else {
30 Ok(r)
31 }
32}
33
34fn cvt_cp<T>(r: *const T) -> Result<*const T, ErrorStack> {
35 if r.is_null() {
36 Err(ErrorStack::get())
37 } else {
38 Ok(r)
39 }
40}
41
42fn cvt(r: c_int) -> Result<c_int, ErrorStack> {
43 if r <= 0 {
44 Err(ErrorStack::get())
45 } else {
46 Ok(r)
47 }
48}