1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use libc::{c_char, c_int, c_long, c_uchar, c_uint, size_t}; 15 16 pub(crate) enum EVP_PKEY {} 17 18 extern "C" { EVP_PKEY_free(ctx: *mut EVP_PKEY)19 pub(crate) fn EVP_PKEY_free(ctx: *mut EVP_PKEY); 20 } 21 22 pub(crate) enum EVP_MD_CTX {} 23 24 pub(crate) enum EVP_MD {} 25 26 extern "C" { EVP_MD_CTX_new() -> *mut EVP_MD_CTX27 pub(crate) fn EVP_MD_CTX_new() -> *mut EVP_MD_CTX; 28 EVP_sha256() -> *mut EVP_MD29 pub(crate) fn EVP_sha256() -> *mut EVP_MD; 30 EVP_DigestInit(ctx: *mut EVP_MD_CTX, md: *mut EVP_MD) -> c_int31 pub(crate) fn EVP_DigestInit(ctx: *mut EVP_MD_CTX, md: *mut EVP_MD) -> c_int; 32 EVP_MD_CTX_free(ctx: *mut EVP_MD_CTX)33 pub(crate) fn EVP_MD_CTX_free(ctx: *mut EVP_MD_CTX); 34 EVP_DigestUpdate(ctx: *mut EVP_MD_CTX, buf: *const c_uchar, cnt: c_int) -> c_int35 pub(crate) fn EVP_DigestUpdate(ctx: *mut EVP_MD_CTX, buf: *const c_uchar, cnt: c_int) -> c_int; 36 EVP_DigestFinal_ex( ctx: *mut EVP_MD_CTX, buf: *const c_uchar, start: *const c_uint, )37 pub(crate) fn EVP_DigestFinal_ex( 38 ctx: *mut EVP_MD_CTX, 39 buf: *const c_uchar, 40 start: *const c_uint, 41 ); 42 } 43 44 pub(crate) enum C_X509 {} 45 46 // for `C_X509` 47 extern "C" { X509_free(a: *mut C_X509)48 pub(crate) fn X509_free(a: *mut C_X509); 49 50 /// Returns a human readable error string for verification error n. X509_verify_cert_error_string(n: c_long) -> *const c_char51 pub(crate) fn X509_verify_cert_error_string(n: c_long) -> *const c_char; 52 53 /// Attempts to decode len bytes at *ppin. 54 /// If successful a pointer to the TYPE structure is returned and *ppin is 55 /// incremented to the byte following the parsed data. d2i_X509( a: *mut *mut C_X509, pp: *mut *const c_uchar, length: c_long, ) -> *mut C_X50956 pub(crate) fn d2i_X509( 57 a: *mut *mut C_X509, 58 pp: *mut *const c_uchar, 59 length: c_long, 60 ) -> *mut C_X509; 61 X509_get_version(a: *const C_X509) -> c_long62 pub(crate) fn X509_get_version(a: *const C_X509) -> c_long; 63 X509_get_subject_name(a: *const C_X509) -> *mut X509_NAME64 pub(crate) fn X509_get_subject_name(a: *const C_X509) -> *mut X509_NAME; 65 X509_get_issuer_name(a: *const C_X509) -> *mut X509_NAME66 pub(crate) fn X509_get_issuer_name(a: *const C_X509) -> *mut X509_NAME; 67 X509_NAME_oneline( a: *mut X509_NAME, buf: *mut c_char, size: c_int, ) -> *mut c_char68 pub(crate) fn X509_NAME_oneline( 69 a: *mut X509_NAME, 70 buf: *mut c_char, 71 size: c_int, 72 ) -> *mut c_char; 73 X509_get_pubkey(a: *mut C_X509) -> *mut EVP_PKEY74 pub(crate) fn X509_get_pubkey(a: *mut C_X509) -> *mut EVP_PKEY; 75 X509_verify(a: *mut C_X509, pkey: *mut EVP_PKEY) -> c_int76 pub(crate) fn X509_verify(a: *mut C_X509, pkey: *mut EVP_PKEY) -> c_int; 77 X509_up_ref(x: *mut C_X509) -> c_int78 pub(crate) fn X509_up_ref(x: *mut C_X509) -> c_int; 79 } 80 pub(crate) enum X509_NAME {} 81 82 extern "C" { X509_NAME_free(name: *mut X509_NAME)83 pub(crate) fn X509_NAME_free(name: *mut X509_NAME); 84 } 85 pub(crate) enum X509_STORE {} 86 87 // for `X509_STORE` 88 extern "C" { 89 /// Returns a new `X509_STORE`. X509_STORE_new() -> *mut X509_STORE90 pub(crate) fn X509_STORE_new() -> *mut X509_STORE; 91 92 /// Frees up a single `X509_STORE` object. X509_STORE_free(store: *mut X509_STORE)93 pub(crate) fn X509_STORE_free(store: *mut X509_STORE); 94 95 /// Adds the respective object to the X509_STORE's local storage. X509_STORE_add_cert(store: *mut X509_STORE, x: *mut C_X509) -> c_int96 pub(crate) fn X509_STORE_add_cert(store: *mut X509_STORE, x: *mut C_X509) -> c_int; 97 98 /// Adds the respective object of file paths to the X509_STORE's local 99 /// storage. 100 #[cfg(feature = "c_openssl_3_0")] X509_STORE_load_path(store: *mut X509_STORE, x: *const c_char) -> c_int101 pub(crate) fn X509_STORE_load_path(store: *mut X509_STORE, x: *const c_char) -> c_int; 102 } 103 104 pub(crate) enum X509_STORE_CTX {} 105 106 extern "C" { X509_STORE_CTX_free(ctx: *mut X509_STORE_CTX)107 pub(crate) fn X509_STORE_CTX_free(ctx: *mut X509_STORE_CTX); 108 X509_STORE_CTX_get0_cert(ctx: *const X509_STORE_CTX) -> *mut C_X509109 pub(crate) fn X509_STORE_CTX_get0_cert(ctx: *const X509_STORE_CTX) -> *mut C_X509; 110 } 111 112 pub(crate) enum X509_VERIFY_PARAM {} 113 114 // for `X509_VERIFY_PARAM` 115 extern "C" { X509_VERIFY_PARAM_free(param: *mut X509_VERIFY_PARAM)116 pub(crate) fn X509_VERIFY_PARAM_free(param: *mut X509_VERIFY_PARAM); 117 X509_VERIFY_PARAM_set_hostflags(param: *mut X509_VERIFY_PARAM, flags: c_uint)118 pub(crate) fn X509_VERIFY_PARAM_set_hostflags(param: *mut X509_VERIFY_PARAM, flags: c_uint); 119 120 /// If name is NUL-terminated, namelen may be zero, otherwise namelen must 121 /// be set to the length of name. X509_VERIFY_PARAM_set1_host( param: *mut X509_VERIFY_PARAM, name: *const c_char, namelen: size_t, ) -> c_int122 pub(crate) fn X509_VERIFY_PARAM_set1_host( 123 param: *mut X509_VERIFY_PARAM, 124 name: *const c_char, 125 namelen: size_t, 126 ) -> c_int; 127 128 /// The ip argument is in binary format, in network byte-order and iplen 129 /// must be set to 4 for IPv4 and 16 for IPv6. X509_VERIFY_PARAM_set1_ip( param: *mut X509_VERIFY_PARAM, ip: *const c_uchar, iplen: size_t, ) -> c_int130 pub(crate) fn X509_VERIFY_PARAM_set1_ip( 131 param: *mut X509_VERIFY_PARAM, 132 ip: *const c_uchar, 133 iplen: size_t, 134 ) -> c_int; 135 } 136 137 pub(crate) enum STACK_X509 {} 138 pub(crate) enum X509_PUBKEY {} 139 140 extern "C" { X509_get_X509_PUBKEY(x509: *mut C_X509) -> *mut X509_PUBKEY141 pub(crate) fn X509_get_X509_PUBKEY(x509: *mut C_X509) -> *mut X509_PUBKEY; 142 X509_PUBKEY_free(x509: *mut X509_PUBKEY)143 pub(crate) fn X509_PUBKEY_free(x509: *mut X509_PUBKEY); 144 i2d_X509_PUBKEY(pubkey: *const X509_PUBKEY, buf: *mut *const c_uchar) -> c_int145 pub(crate) fn i2d_X509_PUBKEY(pubkey: *const X509_PUBKEY, buf: *mut *const c_uchar) -> c_int; 146 } 147