XU XUv0.8.8
EN

API

#crypto/tls

import: #crypto/tls

counts: 10 函数, 12 方法, 4 类型, 5 常量, 0 方法集

TLS 客户端子集。握手走宿主平台库(macOS SecureTransport;Linux/Windows 目前 throw)。

const version_tls12

XuAPI
pub const version_tls12 = 771

用途

公开常量 `version_tls12`。 值为 `771`

参数

无

const version_tls13

XuAPI
pub const version_tls13 = 772

用途

公开常量 `version_tls13`。 值为 `772`

参数

无

const tls_aes_128_gcm_sha256

XuAPI
pub const tls_aes_128_gcm_sha256 = 4865

用途

公开常量 `tls_aes_128_gcm_sha256`。 值为 `4865`

参数

无

const tls_rsa_with_aes_128_gcm_sha256

XuAPI
pub const tls_rsa_with_aes_128_gcm_sha256 = 156

用途

公开常量 `tls_rsa_with_aes_128_gcm_sha256`。 值为 `156`

参数

无

const tls_ecdhe_rsa_with_aes_128_gcm_sha256

XuAPI
pub const tls_ecdhe_rsa_with_aes_128_gcm_sha256 = 49199

用途

公开常量 `tls_ecdhe_rsa_with_aes_128_gcm_sha256`。 值为 `49199`

参数

无

struct Config

XuAPI
pub struct Config {
    pub server_name string
    pub insecure_skip_verify bool
    pub root_cas x509.CertPool
    pub cert_pem string
    pub key_pem string
}

用途

公开结构体 `Config`。

参数

server_name string
字段(string)
insecure_skip_verify bool
字段(bool)
root_cas x509.CertPool
字段(x509.CertPool)
cert_pem string
字段(string)
key_pem string
字段(string)

struct Dialer

XuAPI
pub struct Dialer {
    pub timeout_ns int
    pub config Config
}

用途

公开结构体 `Dialer`。

参数

timeout_ns int
超时(纳秒)
config Config
字段(Config)

struct Conn

XuAPI
pub struct Conn {
    pub server_name string
    pub handshake_complete bool
    pub cipher_suite int
    pub version int
    pub read_deadline_ns int
    pub write_deadline_ns int
}

用途

公开结构体 `Conn`。

参数

server_name string
字段(string)
handshake_complete bool
字段(bool)
cipher_suite int
字段(int)
version int
字段(int)
read_deadline_ns int
字段(int)
write_deadline_ns int
字段(int)

struct ConnectionState

XuAPI
pub struct ConnectionState {
    pub server_name string
    pub handshake_complete bool
    pub cipher_suite int
    pub version int
}

用途

公开结构体 `ConnectionState`。

参数

server_name string
字段(string)
handshake_complete bool
字段(bool)
cipher_suite int
字段(int)
version int
字段(int)

new_config

XuAPI
pub fn new_config(server_name string) Config

用途

构造 config。

参数

server_name string
server_name(string)

返回

Config — 该类型的值

new_dialer

XuAPI
pub fn new_dialer() Dialer

用途

构造 dialer。

参数

无

返回

Dialer — 该类型的值

closed_conn

XuAPI
pub fn closed_conn() Conn

用途

closed连接。

参数

无

返回

Conn — 该类型的值

client

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

用途

客户端。失败时 throw。

参数

c net.Conn
字节或字符码(net.Conn)
config &Config
config(借用,调用方仍持有;类型 &Config)

返回

Conn — 该类型的值

client_pipe

XuAPI
pub fn client_pipe(c net.PipeConn, config &Config) Conn

用途

客户端pipe。失败时 throw。

参数

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

返回

Conn — 该类型的值

server

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

用途

服务端。失败时 throw。

参数

c net.Conn
字节或字符码(net.Conn)
config &Config
config(借用,调用方仍持有;类型 &Config)

返回

Conn — 该类型的值

server_pipe

XuAPI
pub fn server_pipe(c net.PipeConn, config &Config) Conn

用途

服务端pipe。失败时 throw。

参数

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

返回

Conn — 该类型的值

client_fd

XuAPI
pub fn client_fd(fd int, server_name string) Conn

用途

客户端fd。失败时 throw。

参数

fd int
文件描述符(int)
server_name string
server_name(string)

返回

Conn — 该类型的值

dial

XuAPI
pub fn dial(network string, addr string, config &Config) Conn

用途

发起连接。失败时 throw。

参数

network string
network(string)
addr string
地址(string)
config &Config
config(借用,调用方仍持有;类型 &Config)

返回

Conn — 该类型的值

dial_context

XuAPI
pub fn dial_context(ctx &context.Context, network string, addr string, config &Config) Conn

用途

带上下文拨号。失败时 throw。

参数

ctx &context.Context
ctx(借用,调用方仍持有;类型 &context.Context)
network string
network(string)
addr string
地址(string)
config &Config
config(借用,调用方仍持有;类型 &Config)

返回

Conn — 该类型的值

(Dialer) dial

XuAPI
pub fn (d Dialer) dial(network string, addr string) Conn

用途

`Dialer` 上的方法:发起连接。失败时 throw。

参数

d Dialer
接收者 Dialer(值接收者)
network string
network(string)
addr string
地址(string)

返回

Conn — 该类型的值

(Dialer) dial_context

XuAPI
pub fn (d Dialer) dial_context(ctx &context.Context, network string, addr string) Conn

用途

`Dialer` 上的方法:带上下文拨号。失败时 throw。

参数

d Dialer
接收者 Dialer(值接收者)
ctx &context.Context
ctx(借用,调用方仍持有;类型 &context.Context)
network string
network(string)
addr string
地址(string)

返回

Conn — 该类型的值

(&Conn) handshake

XuAPI
pub fn (c &Conn) handshake() int

用途

在 `&Conn` 上调用 `handshake`。失败时 throw。

参数

c &Conn
接收者 &Conn(借用)

返回

int — 该类型的值

(Conn) connection_state

XuAPI
pub fn (c Conn) connection_state() ConnectionState

用途

`Conn` 上的方法:connectionstate。

参数

c Conn
接收者 Conn(值接收者)

返回

ConnectionState — 该类型的值

(&mut Conn) set_deadline

XuAPI
pub fn (c &mut Conn) set_deadline(t_ns int) int

用途

`&mut Conn` 上的方法:设置 deadline。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
t_ns int
t_ns(int)

返回

int — 该类型的值

(&mut Conn) set_read_deadline

XuAPI
pub fn (c &mut Conn) set_read_deadline(t_ns int) int

用途

`&mut Conn` 上的方法:设置 read deadline。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
t_ns int
t_ns(int)

返回

int — 该类型的值

(&mut Conn) set_write_deadline

XuAPI
pub fn (c &mut Conn) set_write_deadline(t_ns int) int

用途

`&mut Conn` 上的方法:设置 write deadline。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
t_ns int
t_ns(int)

返回

int — 该类型的值

(&mut Conn) read

XuAPI
pub fn (c &mut Conn) read(max int) string

用途

`&mut Conn` 上的方法:读出最多 max 字节。失败时 throw。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
max int
上限(int)

返回

string — 结果字符串

(&mut Conn) write

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

用途

`&mut Conn` 上的方法:写入数据,返回写入的字节数。失败时 throw。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
data &string
数据(借用,调用方仍持有;类型 &string)

返回

int — 写入的字节数

(&mut Conn) close

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

用途

`&mut Conn` 上的方法:关闭资源。失败时 throw。

参数

c &mut Conn
接收者 &mut Conn(可变借用)

返回

int — 该类型的值

(&mut Conn) read_result

XuAPI
pub fn (c &mut Conn) read_result(n int) io.ReadResult

用途

`&mut Conn` 上的方法:读取结果。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
n int
数量、长度或上限(int)

返回

io.ReadResult — 该类型的值

(&mut Conn) write_result

XuAPI
pub fn (c &mut Conn) write_result(data string) io.WriteResult

用途

`&mut Conn` 上的方法:写入结果。

参数

c &mut Conn
接收者 &mut Conn(可变借用)
data string
数据(string)

返回

io.WriteResult — 该类型的值