XU XUv0.16.0

#crypto/gmtls

import: #crypto/gmtls

counts: 4 functions, 3 methods, 2 types, 5 constants, 0 method sets

GMTLS 1.1 subset (dual SM2 certs + SM4). In-process net.pipe; no Listen. Pure Xu, not commercial-crypto certified.

const VERSION_GMTLS11

XuAPI
pub const VERSION_GMTLS11 = 257

Purpose

Constant VERSION_GMTLS11, defining protocol or algorithm parameters.

const ECC_SM4_GCM_SM3

XuAPI
pub const ECC_SM4_GCM_SM3 = 57427

Purpose

Constant ECC_SM4_GCM_SM3, defining protocol or algorithm parameters.

const ECDHE_SM4_GCM_SM3

XuAPI
pub const ECDHE_SM4_GCM_SM3 = 57425

Purpose

Constant ECDHE_SM4_GCM_SM3, defining protocol or algorithm parameters.

const ECC_SM4_CBC_SM3

XuAPI
pub const ECC_SM4_CBC_SM3 = 57363

Purpose

Constant ECC_SM4_CBC_SM3, defining protocol or algorithm parameters.

const ECDHE_SM4_CBC_SM3

XuAPI
pub const ECDHE_SM4_CBC_SM3 = 57361

Purpose

Constant ECDHE_SM4_CBC_SM3, defining protocol or algorithm parameters.

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
}

Purpose

sign_key / enc_key: 32-byte raw d, PKCS#8/SEC1 DER, or PEM (PRIVATE KEY / EC PRIVATE KEY / SM2 PRIVATE KEY). sign_cert / enc_cert: DER or PEM CERTIFICATE / X509 CERTIFICATE. server_name: ClientHello SNI (RFC 6066) when non-empty; client also matches it against the server sign certificate DNS SAN / CN unless empty or insecure_skip_verify. client_name: ECDHE server matches it against the client sign certificate DNS SAN / CN unless empty or insecure_skip_verify (does not check the encryption certificate). ECDHE client Config.sign_cert/enc_cert are the client's dual certs and need not match the server. Conn.peer_sign_cert / peer_enc_cert are the peer's presented dual certs (DER). ECC server leaves them empty (no client certs).

Public fields

server_name string
field (string)
client_name string
field (string)
insecure_skip_verify bool
field (bool)
sign_cert string
field (string)
sign_key string
field (string)
enc_cert string
field (string)
enc_key string
field (string)
cipher_suite int
field (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
}

Purpose

Structure encapsulating handshake_complete, cipher_suite, server_name, peer_sign_cert, peer_enc_cert.

Public fields

handshake_complete bool
field (bool)
cipher_suite int
field (int)
server_name string
field (string)
peer_sign_cert string
field (string)
peer_enc_cert string
field (string)

client

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

Purpose

Execute client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c net.PipeConn
byte or character code (net.PipeConn)
cfg &Config
cfg (read-only borrow; caller keeps the original; type &Config)

Returns

Conn — a value of this type

client_with_roots

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

Purpose

Client with roots. Throws on failure; handle the error or propagate it to the caller.

Parameters

c net.PipeConn
byte or character code (net.PipeConn)
cfg &Config
cfg (read-only borrow; caller keeps the original; type &Config)
roots &x509.CertPool
roots (read-only borrow; caller keeps the original; type &x509.CertPool)

Returns

Conn — a value of this type

server

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

Purpose

Execute server. Throws on failure; handle the error or propagate it to the caller.

Parameters

c net.PipeConn
byte or character code (net.PipeConn)
cfg &Config
cfg (read-only borrow; caller keeps the original; type &Config)

Returns

Conn — a value of this type

server_with_roots

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

Purpose

Server with roots. Throws on failure; handle the error or propagate it to the caller.

Parameters

c net.PipeConn
byte or character code (net.PipeConn)
cfg &Config
cfg (read-only borrow; caller keeps the original; type &Config)
roots &x509.CertPool
roots (read-only borrow; caller keeps the original; type &x509.CertPool)

Returns

Conn — a value of this type

($&Conn) write

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

Purpose

Operation on $&Conn: write data and return the byte count. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — bytes written

($&Conn) read

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

Purpose

Operation on $&Conn: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).

Returns

string — result string

($&Conn) close

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

Purpose

Operation on $&Conn: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).

Returns

int — a value of this type