---@meta ssl.x509

--------------------------------------------------------------------------------
-- LuaSec X509 C module
--------------------------------------------------------------------------------

---@class ssl_x509_name_entry
---@field oid string OID
---@field name string Name
---@field value string value

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

---@class ssl_x509*
---@type ssl_x509*
local M = {}

--- Load certificate from PEM or DER string.
---@param data string Certificate data
---@return ssl_x509_certificate*? cert certificate object
function M.load(data) end

--- Compute certificate summary.
---@param digest? 'sha1'|'sha256'|'sha512' summary algorithm
---@return string? digest Digest hex string
---@return string? errMsg error message
function ssl_x509_certificate:digest(digest) end

--- Set the name field encoding.
---@param encoding 'ai5'|'utf8' encoding
---@return boolean ok Is it successful?
function ssl_x509_certificate:setencode(encoding) end

--- Get extension fields.
---@return table extensions extension fields
function ssl_x509_certificate:extensions() end

--- Get the signature algorithm name.
---@return string? name Signature algorithm name
function ssl_x509_certificate:getsignaturename() end

--- Get the issuer.
---@return ssl_x509_name_entry[] issuer Issuer field
function ssl_x509_certificate:issuer() end

--- Get the Not Before time text.
---@return string notBefore time text
function ssl_x509_certificate:notbefore() end

--- Get the Not After time text.
---@return string notAfter time text
function ssl_x509_certificate:notafter() end

--- Get Not Before Unix timestamp.
---@return integer notBefore Timestamp
function ssl_x509_certificate:notbefore_t() end

--- Get Not After Unix timestamp.
---@return integer notAfter Timestamp
function ssl_x509_certificate:notafter_t() end

--- Check if it is issued by another certificate.
---@param issuer ssl_x509_certificate* Issuer certificate
---@return boolean issued Whether to issue
function ssl_x509_certificate:issued(issuer) end

--- Export PEM.
---@return string? pem PEM content
---@return string? errMsg error message
function ssl_x509_certificate:pem() end

--- Export the public key.
---@return string? publicKey Public key PEM
---@return string? errMsg error message
function ssl_x509_certificate:pubkey() end

--- Get the serial number.
---@return string serial serial number
function ssl_x509_certificate:serial() end

--- Get subject.
---@return ssl_x509_name_entry[] subject subject Field
function ssl_x509_certificate:subject() end

--- Checks whether the certificate is valid at a given point in time.
---@param time integer Unix Timestamp
---@return boolean valid Is it valid?
function ssl_x509_certificate:validat(time) end

return M
