XU XUv0.16.0

#crypto/gmtls

导入方式: #crypto/gmtls

公开 API: 4 函数, 3 方法, 2 类型, 5 常量, 0 方法集

GMTLS 1.1 子集(SM2 双证 + SM4)。进程内 net.pipe,无 Listen。零 C、非商密认证。

const VERSION_GMTLS11

XuAPI
pub const VERSION_GMTLS11 = 257

用途

常量 VERSION_GMTLS11,定义了相关的协议或算法配置参数。

const ECC_SM4_GCM_SM3

XuAPI
pub const ECC_SM4_GCM_SM3 = 57427

用途

常量 ECC_SM4_GCM_SM3,定义了相关的协议或算法配置参数。

const ECDHE_SM4_GCM_SM3

XuAPI
pub const ECDHE_SM4_GCM_SM3 = 57425

用途

常量 ECDHE_SM4_GCM_SM3,定义了相关的协议或算法配置参数。

const ECC_SM4_CBC_SM3

XuAPI
pub const ECC_SM4_CBC_SM3 = 57363

用途

常量 ECC_SM4_CBC_SM3,定义了相关的协议或算法配置参数。

const ECDHE_SM4_CBC_SM3

XuAPI
pub const ECDHE_SM4_CBC_SM3 = 57361

用途

常量 ECDHE_SM4_CBC_SM3,定义了相关的协议或算法配置参数。

struct Config

XuAPI
pub struct Config {
    pub server_name string
    pub client_name string
    pub insecure_skip_verify bool
    pub sign_cert string
    pub sign_key string
    pub enc_cert string
    pub enc_key string
    pub cipher_suite int
}

用途

Gmtls 配置参数与选项集合。

公开字段

server_name string
字段(string)
client_name string
字段(string)
insecure_skip_verify bool
字段(bool)
sign_cert string
字段(string)
sign_key string
字段(string)
enc_cert string
字段(string)
enc_key string
字段(string)
cipher_suite int
字段(int)

struct Conn

XuAPI
pub struct Conn {
    pub handshake_complete bool
    pub cipher_suite int
    pub server_name string
    pub peer_sign_cert string
    pub peer_enc_cert string
}

用途

承载 handshake_complete、cipher_suite、server_name、peer_sign_cert、peer_enc_cert 等属性的结构体。

公开字段

handshake_complete bool
字段(bool)
cipher_suite int
字段(int)
server_name string
字段(string)
peer_sign_cert string
字段(string)
peer_enc_cert string
字段(string)

client

XuAPI
pub fn client(c net.PipeConn, cfg &Config) Conn

用途

客户端。失败时抛出错误,调用方需处理或继续传播。

参数

c net.PipeConn
字节或字符码(net.PipeConn)
cfg &Config
cfg(只读借用,调用方仍持有原值;类型 &Config)

返回值

Conn — 该类型的值

client_with_roots

XuAPI
pub fn client_with_roots(c net.PipeConn, cfg &Config, roots &x509.CertPool) Conn

用途

执行 client with roots 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c net.PipeConn
字节或字符码(net.PipeConn)
cfg &Config
cfg(只读借用,调用方仍持有原值;类型 &Config)
roots &x509.CertPool
roots(只读借用,调用方仍持有原值;类型 &x509.CertPool)

返回值

Conn — 该类型的值

server

XuAPI
pub fn server(c net.PipeConn, cfg &Config) Conn

用途

服务端。失败时抛出错误,调用方需处理或继续传播。

参数

c net.PipeConn
字节或字符码(net.PipeConn)
cfg &Config
cfg(只读借用,调用方仍持有原值;类型 &Config)

返回值

Conn — 该类型的值

server_with_roots

XuAPI
pub fn server_with_roots(c net.PipeConn, cfg &Config, roots &x509.CertPool) Conn

用途

执行 server with roots 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c net.PipeConn
字节或字符码(net.PipeConn)
cfg &Config
cfg(只读借用,调用方仍持有原值;类型 &Config)
roots &x509.CertPool
roots(只读借用,调用方仍持有原值;类型 &x509.CertPool)

返回值

Conn — 该类型的值

($&Conn) write

XuAPI
pub fn (c $&Conn) write(data &string) int

用途

$&Conn 上的操作:写入数据,返回写入的字节数。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
data &string
数据(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 写入的字节数

($&Conn) read

XuAPI
pub fn (c $&Conn) read() string

用途

$&Conn 上的操作:读出最多 max 字节。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

string — 结果字符串

($&Conn) close

XuAPI
pub fn (c $&Conn) close() int

用途

$&Conn 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值