
--------------------------------------------------------------------------------
-- lua-openssl module
--------------------------------------------------------------------------------

---@alias openssl_format '"pem"'|'"der"'|'"smime"'|'"auto"'|string
---@alias openssl_digest_like string|openssl_evp_digest*|openssl_asn1_object*
---@alias openssl_cipher_like string|openssl_evp_cipher*|openssl_asn1_object*
---@alias openssl_key_like string|openssl_evp_pkey*|openssl_rsa*|openssl_dsa*|openssl_ec_key*
---@alias openssl_cert_like string|openssl_x509*

---@class openssl_engine*
---@field next fun(...): openssl_engine*
---@field prev fun(...): openssl_engine*
---@field add fun(...): boolean
---@field remove fun(...): boolean
---@field register fun(...): boolean
---@field ctrl fun(...): any
---@field id fun(...): string
---@field name fun(...): string
---@field flags fun(...): integer
---@field set_rand_engine fun(...): boolean
---@field load_private_key fun(...): openssl_evp_pkey*
---@field load_public_key fun(...): openssl_evp_pkey*
---@field load_ssl_client_cert fun(...): any
---@field init fun(...): boolean
---@field finish fun(...): boolean
---@field set_default fun(...): boolean
local openssl_engine = {}

---@class openssl_lhash*
---@field parse fun(...): table
---@field export fun(...): string
---@field get_string fun(...): string
---@field get_number fun(...): number
local openssl_lhash = {}

---@class openssl_bio*
---@field read fun(...): string
---@field gets fun(...): string
---@field write fun(...): boolean
---@field puts fun(...): boolean
---@field flush fun(...): boolean
---@field close fun(...): boolean
---@field type fun(...): string
---@field nbio fun(...): any
---@field reset fun(...): boolean
---@field retry fun(...): boolean
---@field pending fun(...): integer
---@field set_callback fun(...): any
---@field push fun(...): openssl_bio*
---@field pop fun(...): openssl_bio*
---@field next fun(...): openssl_bio*
---@field get_md fun(...): openssl_evp_digest*
---@field cipher_status fun(...): boolean
---@field free fun(...): boolean
---@field get_mem fun(...): string
---@field accept fun(...): any
---@field connect fun(...): any
---@field handshake fun(...): boolean
---@field shutdown fun(...): boolean
---@field fd fun(...): integer
---@field ssl fun(...): openssl_ssl*
---@field seek fun(...): boolean
---@field tell fun(...): integer
---@field destroy_pair fun(...): boolean
local openssl_bio = {}

---@class openssl_bio_module*
---@field null fun(...): openssl_bio*
---@field mem fun(...): openssl_bio*
---@field pair fun(...): openssl_bio*, openssl_bio*
---@field socket fun(...): openssl_bio*
---@field dgram fun(...): openssl_bio*
---@field fd fun(...): openssl_bio*
---@field file fun(...): openssl_bio*
---@field filter fun(...): openssl_bio*
---@field accept fun(...): openssl_bio*
---@field connect fun(...): openssl_bio*
local openssl_bio_module = {}

---@class openssl_asn1_object*
---@field nid fun(...): integer
---@field name fun(...): string
---@field ln fun(...): string
---@field sn fun(...): string
---@field txt fun(...): string
---@field dup fun(...): openssl_asn1_object*
---@field data fun(...): string
---@field equals fun(...): boolean
---@field d2i fun(...): openssl_asn1_object*
---@field i2d fun(...): string
local openssl_asn1_object = {}

---@class openssl_asn1_string*
---@field length fun(...): integer
---@field type fun(...): integer
---@field data fun(...): string
---@field dup fun(...): openssl_asn1_string*
---@field toutf8 fun(...): string
---@field toprint fun(...): string
---@field tostring fun(...): string
---@field set fun(...): boolean
---@field get fun(...): string
---@field i2d fun(...): string
---@field d2i fun(...): openssl_asn1_string*
---@field bn fun(...): openssl_bn*
---@field adj fun(...): any
---@field diff fun(...): number
---@field check fun(...): boolean
local openssl_asn1_string = {}

---@class openssl_asn1_type*
---@field type fun(...): integer
---@field octet fun(...): string
---@field cmp fun(...): integer
---@field info fun(...): table
---@field i2d fun(...): string
---@field asn1string fun(...): openssl_asn1_string*
local openssl_asn1_type = {}

---@class openssl_asn1_module*
---@field UNIVERSAL integer
---@field APPLICATION integer
---@field CONTEXT_SPECIFIC integer
---@field PRIVATE integer
---@field CONSTRUCTED integer
---@field OCTET_STRING integer
---@field UTF8STRING integer
---@field IA5STRING integer
---@field UTCTIME integer
---@field GENERALIZEDTIME integer
---@field new_object fun(...): openssl_asn1_object*
---@field new_integer fun(...): openssl_asn1_string*
---@field new_string fun(...): openssl_asn1_string*
---@field new_utctime fun(...): openssl_asn1_string*
---@field new_generalizedtime fun(...): openssl_asn1_string*
---@field new_type fun(...): openssl_asn1_type*
---@field d2i_asn1type fun(...): openssl_asn1_type*
---@field get_object fun(...): openssl_asn1_object*
---@field put_object fun(...): string
---@field tostring fun(...): string
---@field txt2nid fun(...): integer
local openssl_asn1_module = {}

---@class openssl_evp_digest*
---@field new fun(...): openssl_evp_digest_ctx*
---@field info fun(...): table
---@field digest fun(...): string
---@field signInit fun(...): openssl_evp_digest_ctx*
---@field verifyInit fun(...): openssl_evp_digest_ctx*
---@field get_provider_name fun(...): string
local openssl_evp_digest = {}

---@class openssl_evp_digest_ctx*
---@field update fun(...): openssl_evp_digest_ctx*
---@field final fun(...): string
---@field info fun(...): table
---@field reset fun(...): boolean
---@field close fun(...): boolean
---@field data fun(...): any
---@field signUpdate fun(...): openssl_evp_digest_ctx*
---@field signFinal fun(...): string
---@field verifyUpdate fun(...): openssl_evp_digest_ctx*
---@field verifyFinal fun(...): boolean
---@field sign fun(...): string
---@field verify fun(...): boolean
local openssl_evp_digest_ctx = {}

---@class openssl_digest_module*
---@field list fun(...): string[]
---@field get fun(...): openssl_evp_digest*
---@field new fun(...): openssl_evp_digest_ctx*
---@field digest fun(...): string
---@field signInit fun(...): openssl_evp_digest_ctx*
---@field verifyInit fun(...): openssl_evp_digest_ctx*
---@field fetch fun(...): openssl_evp_digest*
local openssl_digest_module = {}

---@class openssl_evp_cipher*
---@field info fun(...): table
---@field new fun(...): openssl_evp_cipher_ctx*
---@field encrypt_new fun(...): openssl_evp_cipher_ctx*
---@field decrypt_new fun(...): openssl_evp_cipher_ctx*
---@field BytesToKey fun(...): string, string
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field cipher fun(...): string
---@field get_provider_name fun(...): string
local openssl_evp_cipher = {}

---@class openssl_evp_cipher_ctx*
---@field init fun(...): boolean
---@field update fun(...): string
---@field final fun(...): string
---@field info fun(...): table
---@field close fun(...): boolean
---@field ctrl fun(...): any
---@field padding fun(...): boolean
local openssl_evp_cipher_ctx = {}

---@class openssl_cipher_module*
---@field EVP_CTRL_GCM_SET_IVLEN integer
---@field EVP_CTRL_GCM_GET_TAG integer
---@field EVP_CTRL_GCM_SET_TAG integer
---@field EVP_CTRL_CCM_SET_IVLEN integer
---@field EVP_CTRL_CCM_GET_TAG integer
---@field EVP_CTRL_CCM_SET_TAG integer
---@field list fun(...): string[]
---@field get fun(...): openssl_evp_cipher*
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field cipher fun(...): string
---@field new fun(...): openssl_evp_cipher_ctx*
---@field encrypt_new fun(...): openssl_evp_cipher_ctx*
---@field decrypt_new fun(...): openssl_evp_cipher_ctx*
---@field fetch fun(...): openssl_evp_cipher*
local openssl_cipher_module = {}

---@class openssl_hmac_ctx*
---@field update fun(...): openssl_hmac_ctx*
---@field final fun(...): string
---@field close fun(...): boolean
---@field size fun(...): integer
local openssl_hmac_ctx = {}

---@class openssl_hmac_module*
---@field new fun(...): openssl_hmac_ctx*
---@field hmac fun(...): string
local openssl_hmac_module = {}

---@class openssl_mac*
---@field is_a fun(...): boolean
---@field names fun(...): string[]
---@field provider fun(...): openssl_provider*
---@field get_params fun(...): table
local openssl_mac = {}

---@class openssl_mac_ctx*
---@field update fun(...): openssl_mac_ctx*
---@field final fun(...): string
---@field close fun(...): boolean
---@field size fun(...): integer
---@field dup fun(...): openssl_mac_ctx*
---@field mac fun(...): string
---@field params fun(...): table
local openssl_mac_ctx = {}

---@class openssl_mac_module*
---@field ctx fun(...): openssl_mac_ctx*
---@field new fun(...): openssl_mac_ctx*
---@field mac fun(...): string
local openssl_mac_module = {}

---@class openssl_kdf*
---@field description fun(...): string
---@field name fun(...): string
---@field provider fun(...): openssl_provider*
---@field is_a fun(...): boolean
---@field iterator fun(...): any
---@field derive fun(...): string
---@field new fun(...): openssl_kdf_ctx*
---@field gettable_params fun(...): table
---@field settable_ctx_params fun(...): table
---@field gettable_ctx_params fun(...): table
---@field get_params fun(...): table
local openssl_kdf = {}

---@class openssl_kdf_ctx*
---@field dup fun(...): openssl_kdf_ctx*
---@field reset fun(...): boolean
---@field derive fun(...): string
---@field size fun(...): integer
---@field kdf fun(...): openssl_kdf*
---@field gettable_params fun(...): table
---@field settable_params fun(...): table
---@field get_params fun(...): table
---@field set_params fun(...): boolean
local openssl_kdf_ctx = {}

---@class openssl_kdf_module*
---@field fetch fun(...): openssl_kdf*
---@field iterator fun(...): any
---@field derive fun(...): string
local openssl_kdf_module = {}

---@class openssl_evp_pkey*
---@field is_private fun(...): boolean
---@field get_public fun(...): openssl_evp_pkey*
---@field set_engine fun(...): boolean
---@field export fun(...): string
---@field parse fun(...): table
---@field bits fun(...): integer
---@field ctx fun(...): openssl_evp_pkey_ctx*
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field sign fun(...): string
---@field verify fun(...): boolean
---@field seal fun(...): string
---@field open fun(...): string
---@field derive fun(...): string
---@field as_sm2 fun(...): openssl_evp_pkey*
---@field missing_paramaters fun(...): boolean
local openssl_evp_pkey = {}

---@class openssl_evp_pkey_ctx*
---@field encrypt_init fun(...): boolean
---@field decrypt_init fun(...): boolean
---@field verify_init fun(...): boolean
---@field sign_init fun(...): boolean
---@field ctrl fun(...): any
---@field keygen fun(...): openssl_evp_pkey*
---@field decrypt fun(...): string
---@field encrypt fun(...): string
---@field verify fun(...): boolean
---@field sign fun(...): string
local openssl_evp_pkey_ctx = {}

---@class openssl_pkey_module*
---@field read fun(...): openssl_evp_pkey*
---@field new fun(...): openssl_evp_pkey*
---@field ctx_new fun(...): openssl_evp_pkey_ctx*
---@field seal fun(...): any
---@field seal_init fun(...): any
---@field seal_update fun(...): any
---@field seal_final fun(...): any
---@field open fun(...): any
---@field open_init fun(...): any
---@field open_update fun(...): any
---@field open_final fun(...): any
---@field get_public fun(...): openssl_evp_pkey*
---@field set_engine fun(...): boolean
---@field is_private fun(...): boolean
---@field export fun(...): string
---@field parse fun(...): table
---@field bits fun(...): integer
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field sign fun(...): string
---@field verify fun(...): boolean
---@field derive fun(...): string
---@field as_sm2 fun(...): openssl_evp_pkey*
local openssl_pkey_module = {}

---@class openssl_bn*
---@field abs fun(...): openssl_bn*
---@field add fun(...): openssl_bn*
---@field addmod fun(...): openssl_bn*
---@field aprime fun(...): openssl_bn*
---@field bits fun(...): integer
---@field compare fun(...): integer
---@field div fun(...): openssl_bn*
---@field divmod fun(...): openssl_bn*, openssl_bn*
---@field gcd fun(...): openssl_bn*
---@field invmod fun(...): openssl_bn*
---@field isneg fun(...): boolean
---@field isodd fun(...): boolean
---@field isone fun(...): boolean
---@field isprime fun(...): boolean
---@field iszero fun(...): boolean
---@field mod fun(...): openssl_bn*
---@field mul fun(...): openssl_bn*
---@field mulmod fun(...): openssl_bn*
---@field neg fun(...): openssl_bn*
---@field number fun(...): openssl_bn*
---@field pow fun(...): openssl_bn*
---@field powmod fun(...): openssl_bn*
---@field random fun(...): openssl_bn*
---@field rmod fun(...): openssl_bn*
---@field sqr fun(...): openssl_bn*
---@field sqrmod fun(...): openssl_bn*
---@field sqrtmod fun(...): openssl_bn*
---@field sub fun(...): openssl_bn*
---@field submod fun(...): openssl_bn*
---@field text fun(...): openssl_bn*
---@field tohex fun(...): string
---@field totext fun(...): string
---@field tonumber fun(...): number
---@field tostring fun(...): string
---@field version string
local openssl_bn = {}

---@class openssl_rsa*
---@field parse fun(...): table
---@field isprivate fun(...): boolean
---@field export fun(...): string
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field sign fun(...): string
---@field verify fun(...): boolean
---@field size fun(...): integer
---@field set_engine fun(...): boolean
local openssl_rsa = {}

---@class openssl_rsa_module*
---@field parse fun(...): table
---@field isprivate fun(...): boolean
---@field export fun(...): string
---@field encrypt fun(...): string
---@field decrypt fun(...): string
---@field sign fun(...): string
---@field verify fun(...): boolean
---@field size fun(...): integer
---@field set_engine fun(...): boolean
---@field read fun(...): openssl_rsa*
---@field generate_key fun(...): openssl_rsa*
---@field padding_add fun(...): string
---@field padding_check fun(...): string
local openssl_rsa_module = {}

---@class openssl_dsa*
---@field parse fun(...): table
---@field set_engine fun(...): boolean
local openssl_dsa = {}

---@class openssl_dsa_module*
---@field generate_key fun(...): openssl_dsa*
local openssl_dsa_module = {}

---@class openssl_dh*
---@field generate_key fun(...): boolean
---@field parse fun(...): table
---@field check fun(...): integer
local openssl_dh = {}

---@class openssl_dh_module*
---@field generate_parameters fun(...): openssl_dh*
---@field problems fun(...): string[]
local openssl_dh_module = {}

---@class openssl_ec_point*
---@field copy fun(...): openssl_ec_point*
local openssl_ec_point = {}

---@class openssl_ec_group*
---@field dup fun(...): openssl_ec_group*
---@field generator fun(...): openssl_ec_point*
---@field order fun(...): openssl_bn*
---@field cofactor fun(...): openssl_bn*
---@field degree fun(...): integer
---@field curve_name fun(...): string
---@field asn1_flag fun(...): any
---@field point_conversion_form fun(...): any
---@field curve fun(...): table
---@field seed fun(...): string
---@field parse fun(...): table
---@field equal fun(...): boolean
---@field point_new fun(...): openssl_ec_point*
---@field point_dup fun(...): openssl_ec_point*
---@field point_equal fun(...): boolean
---@field point_add fun(...): openssl_ec_point*
---@field point_dbl fun(...): openssl_ec_point*
---@field point_invert fun(...): openssl_ec_point*
---@field point_mul fun(...): openssl_ec_point*
---@field is_at_infinity fun(...): boolean
---@field is_on_curve fun(...): boolean
---@field point2oct fun(...): string
---@field oct2point fun(...): openssl_ec_point*
---@field point2bn fun(...): openssl_bn*
---@field bn2point fun(...): openssl_ec_point*
---@field point2hex fun(...): string
---@field hex2point fun(...): openssl_ec_point*
---@field affine_coordinates fun(...): any
---@field set_to_infinity fun(...): boolean
---@field generate_key fun(...): openssl_ec_key*
local openssl_ec_group = {}

---@class openssl_ec_key*
---@field check fun(...): boolean
---@field export fun(...): string
---@field parse fun(...): table
---@field group fun(...): openssl_ec_group*
---@field do_sign fun(...): string
---@field do_verify fun(...): boolean
---@field sign fun(...): string
---@field verify fun(...): boolean
---@field compute_key fun(...): string
---@field set_method fun(...): boolean
---@field conv_form fun(...): any
---@field enc_flags fun(...): any
local openssl_ec_key = {}

---@class openssl_ec_group_module*
---@field new fun(...): openssl_ec_group*
---@field list fun(...): string[]
local openssl_ec_group_module = {}

---@class openssl_ec_point_module*
---@field new fun(...): openssl_ec_point*
---@field dup fun(...): openssl_ec_point*
---@field equal fun(...): boolean
---@field add fun(...): openssl_ec_point*
---@field dbl fun(...): openssl_ec_point*
---@field invert fun(...): openssl_ec_point*
---@field mul fun(...): openssl_ec_point*
---@field is_at_infinity fun(...): boolean
---@field is_on_curve fun(...): boolean
---@field point2oct fun(...): string
---@field oct2point fun(...): openssl_ec_point*
---@field point2bn fun(...): openssl_bn*
---@field bn2point fun(...): openssl_ec_point*
---@field point2hex fun(...): string
---@field hex2point fun(...): openssl_ec_point*
---@field affine_coordinates fun(...): any
---@field set_to_infinity fun(...): boolean
local openssl_ec_point_module = {}

---@class openssl_ec_module*
---@field group openssl_ec_group_module*
---@field point openssl_ec_point_module*
---@field read fun(...): openssl_ec_key*
---@field list fun(...): string[]
---@field do_sign fun(...): string
---@field do_verify fun(...): boolean
---@field sign fun(...): string
---@field verify fun(...): boolean
local openssl_ec_module = {}

---@class openssl_x509_name*
---@field oneline fun(...): string
---@field hash fun(...): integer
---@field digest fun(...): string
---@field toprint fun(...): string
---@field info fun(...): table
---@field dup fun(...): openssl_x509_name*
---@field i2d fun(...): string
---@field entry_count fun(...): integer
---@field get_text fun(...): string
---@field get_entry fun(...): any
---@field add_entry fun(...): boolean
---@field delete_entry fun(...): any
---@field cmp fun(...): integer
---@field tostring fun(...): string
local openssl_x509_name = {}

---@class openssl_x509_attribute*
---@field info fun(...): table
---@field dup fun(...): openssl_x509_attribute*
---@field data fun(...): string
---@field type fun(...): integer
---@field object fun(...): openssl_asn1_object*
local openssl_x509_attribute = {}

---@class openssl_x509_extension*
---@field info fun(...): table
---@field dup fun(...): openssl_x509_extension*
---@field export fun(...): string
---@field object fun(...): openssl_asn1_object*
---@field critical fun(...): boolean
---@field data fun(...): string
local openssl_x509_extension = {}

---@class openssl_x509_store*
---@field flags fun(...): any
---@field purpose fun(...): any
---@field depth fun(...): integer
---@field trust fun(...): any
---@field load fun(...): boolean
---@field add fun(...): boolean
---@field add_lookup fun(...): any
---@field certs fun(...): openssl_x509*[]
---@field crls fun(...): openssl_x509_crl*[]
---@field param fun(...): any
---@field verify_cb fun(...): any
---@field verify fun(...): boolean
---@field lookup_crls_cb fun(...): any
local openssl_x509_store = {}

---@class openssl_x509_algor*
---@field dup fun(...): openssl_x509_algor*
---@field set fun(...): boolean
---@field get fun(...): table
---@field md fun(...): openssl_evp_digest*
---@field tostring fun(...): string
---@field equals fun(...): boolean
local openssl_x509_algor = {}

---@class openssl_x509_req*
---@field to_x509 fun(...): openssl_x509*
---@field export fun(...): string
---@field parse fun(...): table
---@field digest fun(...): string
---@field verify fun(...): boolean
---@field check fun(...): boolean
---@field dup fun(...): openssl_x509_req*
---@field sign fun(...): boolean
---@field public fun(...): openssl_evp_pkey*
---@field version fun(...): integer
---@field subject fun(...): openssl_x509_name*
---@field extensions fun(...): openssl_x509_extension*[]
---@field attribute fun(...): openssl_x509_attribute*
---@field attr_count fun(...): integer
local openssl_x509_req = {}

---@class openssl_x509_crl*
---@field sort fun(...): boolean
---@field verify fun(...): boolean
---@field sign fun(...): boolean
---@field digest fun(...): string
---@field diff fun(...): any
---@field version fun(...): integer
---@field issuer fun(...): openssl_x509_name*
---@field lastUpdate fun(...): string
---@field nextUpdate fun(...): string
---@field updateTime fun(...): any
---@field extensions fun(...): openssl_x509_extension*[]
---@field add fun(...): boolean
---@field parse fun(...): table
---@field export fun(...): string
---@field cmp fun(...): integer
---@field count fun(...): integer
---@field get fun(...): openssl_x509_revoked*
local openssl_x509_crl = {}

---@class openssl_x509_revoked*
---@field info fun(...): table
---@field reason fun(...): string
---@field revocationDate fun(...): string
---@field serialNumber fun(...): openssl_bn*
---@field extensions fun(...): openssl_x509_extension*[]
local openssl_x509_revoked = {}

---@class openssl_x509*
---@field parse fun(...): table
---@field export fun(...): string
---@field check fun(...): boolean
---@field check_host fun(...): boolean
---@field check_email fun(...): boolean
---@field check_ip_asc fun(...): boolean
---@field pubkey fun(...): openssl_evp_pkey*
---@field version fun(...): integer
---@field equal fun(...): boolean
---@field digest fun(...): string
---@field extensions fun(...): openssl_x509_extension*[]
---@field issuer fun(...): openssl_x509_name*
---@field notbefore fun(...): string
---@field notafter fun(...): string
---@field serial fun(...): openssl_bn*
---@field subject fun(...): openssl_x509_name*
---@field validat fun(...): boolean
---@field sign fun(...): boolean
---@field verify fun(...): boolean
local openssl_x509 = {}

---@class openssl_x509_name_module*
---@field new fun(...): openssl_x509_name*
---@field d2i fun(...): openssl_x509_name*
local openssl_x509_name_module = {}

---@class openssl_x509_attribute_module*
---@field new_attribute fun(...): openssl_x509_attribute*
local openssl_x509_attribute_module = {}

---@class openssl_x509_extension_module*
---@field support fun(...): table
---@field new_extension fun(...): openssl_x509_extension*
---@field read_extension fun(...): openssl_x509_extension*
local openssl_x509_extension_module = {}

---@class openssl_x509_store_module*
---@field new fun(...): openssl_x509_store*
local openssl_x509_store_module = {}

---@class openssl_x509_algor_module*
---@field new fun(...): openssl_x509_algor*
local openssl_x509_algor_module = {}

---@class openssl_x509_req_module*
---@field new fun(...): openssl_x509_req*
---@field read fun(...): openssl_x509_req*
local openssl_x509_req_module = {}

---@class openssl_x509_crl_module*
---@field new fun(...): openssl_x509_crl*
---@field read fun(...): openssl_x509_crl*
---@field reason fun(...): string
local openssl_x509_crl_module = {}

---@class openssl_x509_module*
---@field name openssl_x509_name_module*
---@field attribute openssl_x509_attribute_module*
---@field extension openssl_x509_extension_module*
---@field store openssl_x509_store_module*
---@field algor openssl_x509_algor_module*
---@field req openssl_x509_req_module*
---@field crl openssl_x509_crl_module*
---@field check_flag table<string, integer>
---@field verify_result table<string, integer>
---@field new fun(...): openssl_x509*
---@field read fun(...): openssl_x509*
---@field purpose fun(...): table
---@field certtypes fun(...): table
---@field verify_cert_error_string fun(...): string
local openssl_x509_module = {}

---@class openssl_pkcs7*
---@field type fun(...): string
---@field parse fun(...): table
---@field export fun(...): string
---@field decrypt fun(...): string
---@field verify fun(...): boolean
---@field add fun(...): boolean
---@field set_content fun(...): boolean
---@field set_digest fun(...): boolean
---@field final fun(...): boolean
local openssl_pkcs7 = {}

---@class openssl_pkcs7_module*
---@field TEXT integer
---@field NOCERTS integer
---@field NOSIGS integer
---@field NOCHAIN integer
---@field DETACHED integer
---@field BINARY integer
---@field STREAM integer
---@field new fun(...): openssl_pkcs7*
---@field create fun(...): openssl_pkcs7*
---@field read fun(...): openssl_pkcs7*
---@field sign fun(...): openssl_pkcs7*
---@field verify fun(...): boolean
---@field encrypt fun(...): openssl_pkcs7*
---@field decrypt fun(...): string
local openssl_pkcs7_module = {}

---@class openssl_pkcs12_module*
---@field read fun(...): table
---@field export fun(...): string
local openssl_pkcs12_module = {}

---@class openssl_cms*
---@field type fun(...): string
---@field content fun(...): string
---@field detached fun(...): boolean
---@field export fun(...): string
---@field data fun(...): string
---@field digest_verify fun(...): boolean
---@field add_signers fun(...): boolean
---@field get_signers fun(...): openssl_x509*[]
---@field add_receipt fun(...): boolean
---@field sign_receipt fun(...): openssl_cms*
---@field verify_receipt fun(...): boolean
---@field final fun(...): boolean
local openssl_cms = {}

---@class openssl_cms_module*
---@field read fun(...): openssl_cms*
---@field export fun(...): string
---@field new fun(...): openssl_cms*
---@field data fun(...): openssl_cms*
---@field compress fun(...): openssl_cms*
---@field uncompress fun(...): string
---@field sign fun(...): openssl_cms*
---@field verify fun(...): boolean
---@field encrypt fun(...): openssl_cms*
---@field decrypt fun(...): string
---@field digest_create fun(...): openssl_cms*
---@field digest_verify fun(...): boolean
---@field EncryptedData_encrypt fun(...): openssl_cms*
---@field EncryptedData_decrypt fun(...): string
local openssl_cms_module = {}

---@class openssl_ocsp_certid*
---@field info fun(...): table
local openssl_ocsp_certid = {}

---@class openssl_ocsp_request*
---@field export fun(...): string
---@field parse fun(...): table
---@field sign fun(...): boolean
---@field add_ext fun(...): boolean
---@field is_signed fun(...): boolean
---@field add fun(...): any
local openssl_ocsp_request = {}

---@class openssl_ocsp_response*
---@field export fun(...): string
---@field parse fun(...): table
local openssl_ocsp_response = {}

---@class openssl_ocsp_basicresp*
---@field info fun(...): table
---@field add fun(...): boolean
---@field add_ext fun(...): boolean
---@field sign fun(...): boolean
---@field response fun(...): openssl_ocsp_response*
---@field copy_nonce fun(...): boolean
local openssl_ocsp_basicresp = {}

---@class openssl_ocsp_module*
---@field certid_new fun(...): openssl_ocsp_certid*
---@field request_read fun(...): openssl_ocsp_request*
---@field request_new fun(...): openssl_ocsp_request*
---@field response_read fun(...): openssl_ocsp_response*
---@field basicresp_new fun(...): openssl_ocsp_basicresp*
local openssl_ocsp_module = {}

---@class openssl_ssl_ctx*
---@field ssl fun(...): openssl_ssl*
---@field bio fun(...): openssl_bio*
---@field use fun(...): boolean
---@field add fun(...): boolean
---@field mode fun(...): any
---@field timeout fun(...): integer
---@field options fun(...): any
---@field version fun(...): integer, integer
---@field num_tickets fun(...): integer
---@field quiet_shutdown fun(...): boolean
---@field verify_locations fun(...): boolean
---@field cert_store fun(...): openssl_x509_store*
---@field set_engine fun(...): boolean
---@field verify_mode fun(...): any
---@field set_cert_verify fun(...): any
---@field set_alpn_protos fun(...): boolean
---@field set_alpn_select_cb fun(...): any
---@field verify_depth fun(...): integer
---@field set_tmp fun(...): boolean
---@field flush_sessions fun(...): boolean
---@field session fun(...): openssl_ssl_session*
---@field session_cache_mode fun(...): any
---@field set_session_callback fun(...): any
---@field set_servername_callback fun(...): any
local openssl_ssl_ctx = {}

---@class openssl_ssl_session*
---@field id fun(...): string
---@field time fun(...): integer
---@field timeout fun(...): integer
---@field compress_id fun(...): integer
---@field peer fun(...): openssl_x509*
---@field export fun(...): string
---@field is_resumable fun(...): boolean
---@field has_ticket fun(...): boolean
local openssl_ssl_session = {}

---@class openssl_ssl*
---@field set fun(...): any
---@field get fun(...): any
---@field use fun(...): boolean
---@field peer fun(...): openssl_x509*
---@field getfd fun(...): integer
---@field is_server fun(...): boolean
---@field current_cipher fun(...): string
---@field current_compression fun(...): string
---@field getpeerverification fun(...): boolean
---@field session fun(...): openssl_ssl_session*
---@field dup fun(...): openssl_ssl*
---@field ctx fun(...): openssl_ssl_ctx*
---@field clear fun(...): boolean
---@field want fun(...): string
---@field pending fun(...): integer
---@field accept fun(...): boolean
---@field connect fun(...): boolean
---@field read fun(...): string
---@field peek fun(...): string
---@field write fun(...): boolean
---@field renegotiate fun(...): boolean
---@field handshake fun(...): boolean
---@field shutdown fun(...): boolean
---@field session_reused fun(...): boolean
---@field set_debug fun(...): any
---@field cache_hit fun(...): boolean
---@field renegotiate_abbreviated fun(...): boolean
---@field renegotiate_pending fun(...): boolean
---@field set_connect_state fun(...): boolean
---@field set_accept_state fun(...): boolean
---@field get_alpn_selected fun(...): string
local openssl_ssl = {}

---@class openssl_ssl_module*
---@field default string
---@field DEFAULT_CIPHER_LIST string
---@field none integer
---@field peer integer
---@field fail_if_no_peer_cert integer
---@field client_once integer
---@field ctx_new fun(...): openssl_ssl_ctx*
---@field alert_type fun(...): string
---@field alert_desc fun(...): string
---@field session_new fun(...): openssl_ssl_session*
---@field session_read fun(...): openssl_ssl_session*
local openssl_ssl_module = {}

---@class openssl_ts_module*
---@field req_new fun(...): any
---@field req_read fun(...): any
---@field resp_read fun(...): any
---@field ts_accuracy_read fun(...): any
---@field ts_msg_imprint_read fun(...): any
---@field resp_ctx_new fun(...): any
---@field verify_ctx_new fun(...): any
---@field ts_accuracy_new fun(...): any
---@field ts_msg_imprint_new fun(...): any
local openssl_ts_module = {}

---@class openssl_provider*
---@field name fun(...): string
---@field available fun(...): boolean
---@field get_params fun(...): table
---@field unload fun(...): boolean
---@field self_test fun(...): boolean
local openssl_provider = {}

---@class openssl_provider_module*
---@field load fun(...): openssl_provider*
---@field list fun(...): openssl_provider*[]
---@field get fun(...): openssl_provider*
---@field _error? string
local openssl_provider_module = {}

---@class openssl_param_info*
---@field type integer OpenSSL OSSL_PARAM 类型
---@field number_type? string 数值类型

---@class openssl_param_module*
---@field kdf table<string, openssl_param_info*>
---@field rsa table<string, openssl_param_info*>
local openssl_param_module = {}

---@class openssl_srp_module*
---@field get_default_gN fun(...): any
---@field calc_x fun(...): string
---@field calc_u fun(...): string
---@field calc_a fun(...): string
---@field calc_client_key fun(...): string
---@field calc_b fun(...): string
---@field create_verifier fun(...): string
---@field calc_server_key fun(...): string
local openssl_srp_module = {}

---@class openssl*
---@field bio openssl_bio_module*
---@field asn1 openssl_asn1_module*
---@field digest openssl_digest_module*
---@field cipher openssl_cipher_module*
---@field hmac openssl_hmac_module*
---@field mac? openssl_mac_module*
---@field param? openssl_param_module*
---@field provider? openssl_provider_module*
---@field kdf openssl_kdf_module*
---@field pkey openssl_pkey_module*
---@field ec? openssl_ec_module*
---@field x509 openssl_x509_module*
---@field pkcs7 openssl_pkcs7_module*
---@field pkcs12 openssl_pkcs12_module*
---@field ocsp openssl_ocsp_module*
---@field ts? openssl_ts_module*
---@field cms openssl_cms_module*
---@field ssl openssl_ssl_module*
---@field bn openssl_bn*
---@field rsa openssl_rsa_module*
---@field dsa openssl_dsa_module*
---@field dh openssl_dh_module*
---@field srp? openssl_srp_module*
---@type openssl*
local M = {}

--- Get lua-openssl, Lua and OpenSSL versions.
---@param numeric? boolean return numeric version values
---@return string|integer luaopenssl_version
---@return string|integer lua_version
---@return string|integer openssl_version
function M.version(numeric) end

--- List OpenSSL method names.
---@param type '"digests"'|'"ciphers"'|'"pkeys"'|'"comps"'
---@return string[] names
function M.list(type) end

--- Hex encode or decode data.
---@param data string
---@param encode? boolean default true
---@return string data
function M.hex(data, encode) end

--- Base64 encode or decode data.
---@param input string|openssl_bio*
---@param encode? boolean default true
---@param noNewline? boolean default true
---@return string data
function M.base64(input, encode, noNewline) end

---@return string report
function M.mem_leaks() end

---@return boolean ok
function M.rand_status() end

---@param seed string
---@param entropy? number
function M.rand_add(seed, entropy) end

---@param file? string
---@param bytes? integer
---@return boolean ok
function M.rand_load(file, bytes) end

---@param file? string
---@return boolean ok
function M.rand_write(file) end

---@param length integer
---@return string bytes
function M.random(length) end

function M.clear_error() end

---@param code? integer
---@return string? reason
---@return string? library
---@return integer? errcode
---@return string? func
---@return boolean? fatal
function M.error(code) end

---@return string errors
function M.errors() end

---@param id string
---@return openssl_engine* engine
function M.engine(id) end

---@param enabled? boolean
---@return boolean ok
function M.FIPS_mode(enabled) end

---@param source string|openssl_bio*
---@param format? openssl_format
---@return openssl_lhash* hash
function M.lhash_read(source, format) end

---@param file string
---@return openssl_lhash* hash
function M.lhash_load(file) end

return M
