
--------------------------------------------------------------------------------
-- LuaSec SSL module
--------------------------------------------------------------------------------

---@class ssl_context*
local ssl_context = {}

---@class ssl_connection*
local ssl_connection = {}

---@type ssl_core*
local core = require("ssl.core")

---@type ssl_context_core*
local context = require("ssl.context")

---@type ssl_x509*
local x509 = require("ssl.x509")

---@type ssl_config_core*
local config = require("ssl.config")

---@class ssl_config*
---@field mode? 'client'|'server' SSL mode
---@field protocol? string agreement
---@field key? string private key path
---@field certificate? string Certificate path
---@field cafile? string CA file path
---@field capath? string CA directory path
---@field verify? string|string[] Validation options
---@field options? string|string[] SSL Options
---@field ciphers? string cipher suite
---@field password? string|function Private key password
---@field alpn? string[] ALPN Protocol list

---@class ssl*
---@field _VERSION string version
---@field _COPYRIGHT string Copyright information
---@field config ssl_config_core* Default configuration
---@type ssl*
local M = {}

M.config = config

--- Create SSL context
---@param cfg ssl_config* Configuration
---@return ssl_context*? context SSL context
---@return string? errMsg error message
function M.newcontext(cfg) end

--- wrap socket as SSL socket
---@param sock any socket object
---@param cfg ssl_config*|ssl_context* SSL configuration or context
---@return ssl_connection*? conn SSL socket
---@return string? errMsg error message
function M.wrap(sock, cfg) end

--- Load certificate
---@param data string Certificate data or path
---@return any certificate certificate object
function M.loadcertificate(data) end

--- Perform SSL handshake
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:dohandshake() end

--- Send data
---@param data string data
---@param from? integer starting position
---@param to? integer end position
---@return integer? sent Number of bytes sent
---@return string? errMsg error message
---@return integer? lastIndex last sent position
function ssl_connection:send(data, from, to) end

--- receive data
---@param pattern? '*l'|'*a'|integer receive mode
---@param prefix? string prefix
---@return string? data data
---@return string? errMsg error message
---@return string? partial partial data
function ssl_connection:receive(pattern, prefix) end

--- Set timeout
---@param timeout number Timeout seconds
---@param mode? string mode
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:settimeout(timeout, mode) end

--- close connection
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:close() end

--- Get connection information
---@param field? string Field name
---@return any info information
---@return string? errMsg error message
function ssl_connection:info(field) end

return M
