---@meta ssl.core

--------------------------------------------------------------------------------
-- LuaSec SSL C core module
--------------------------------------------------------------------------------

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

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

---@class ssl_core*
---@field SOCKET_INVALID integer Invalid socket fd
---@type ssl_core*
local M = {}

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

--- Create an SSL connection object.
---@param context ssl_context* SSL context
---@return ssl_connection*? conn SSL connection
---@return string? errMsg error message
function M.create(context) end

--- Query the current connection compression algorithm.
---@param conn ssl_connection* SSL connection
---@return string? compression Compression algorithm
---@return string? errMsg error message
function M.compression(conn) end

--- Query the cipher suite information of the SSL connection.
---@param conn ssl_connection* SSL connection
---@return string? cipherInfo Cipher suite description
---@return integer? bits number of key digits
---@return integer? algbits Algorithm number of digits
---@return string? protocol Protocol version
function M.info(conn) end

--- Bind the underlying fd.
---@param conn ssl_connection* SSL connection
---@param fd integer file descriptor
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function M.setfd(conn, fd) end

--- Register Lua methods for SSL connection.
---@param name string method name
---@param fn function Method implementation
function M.setmethod(name, fn) end

--- Return LuaSec copyright information.
---@return string copyright Copyright information
function M.copyright() end

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

--- Get the ALPN protocol.
---@return string? protocol ALPN agreement
function ssl_connection:getalpn() end

--- Get the underlying fd.
---@return integer fd file descriptor
function ssl_connection:getfd() end

--- Get the local finished message.
---@return string? data finished news
function ssl_connection:getfinished() end

--- Obtain the peer certificate.
---@return ssl_x509_certificate*? cert certificate object
function ssl_connection:getpeercertificate() end

--- Get the local certificate.
---@return ssl_x509_certificate*? cert certificate object
function ssl_connection:getlocalcertificate() end

--- Get the peer certificate chain.
---@return ssl_x509_certificate[]? chain certificate chain
function ssl_connection:getpeerchain() end

--- Get the local certificate chain.
---@return ssl_x509_certificate[]? chain certificate chain
function ssl_connection:getlocalchain() end

--- Get the peer certificate verification result.
---@return boolean ok Whether it passes the verification
---@return table? errors Check error list
function ssl_connection:getpeerverification() end

--- Get the peer finished message.
---@return string? data finished news
function ssl_connection:getpeerfinished() end

--- Export keying material.
---@param label string label
---@param length integer Output length
---@param context? string context
---@return string? material keying material
---@return string? errMsg error message
function ssl_connection:exportkeyingmaterial(label, length, context) end

--- Get transfer statistics.
---@return integer received Number of bytes received
---@return integer sent Number of bytes sent
---@return number age seconds after creation
function ssl_connection:getstats() end

--- Set transfer statistics.
---@param received? integer Number of bytes received
---@param sent? integer Number of bytes sent
---@param age? number seconds after creation
---@return integer? ok Returns 1 on success
function ssl_connection:setstats(received, sent, age) end

--- Check whether there is unread data in the buffer.
---@return boolean dirty Is there any unread data?
function ssl_connection:dirty() end

--- Perform an SSL handshake.
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:dohandshake() 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

--- 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

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

--- Set SNI name.
---@param name string SNI Name
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:sni(name) end

--- Get the SNI name.
---@return string? name SNI Name
function ssl_connection:getsniname() end

--- Returns the current waiting direction.
---@return 'read'|'write'|string? want waiting direction
function ssl_connection:want() end

--- Enable DANE.
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:setdane() end

--- Set up TLSA records.
---@param usage integer usage
---@param selector integer selector
---@param matchingType integer matching type
---@param data string TLSA data
---@return boolean? ok Is it successful?
---@return string? errMsg error message
function ssl_connection:settlsa(usage, selector, matchingType, data) end

return M
