CoolrfulDARkness/moontlcp/state does not have a README file

    StateError

    pub suberror StateError {
    ProtocolError(
    AlertDescription
    , String)
    RecordError(String)
    CertificateError(String)
    CryptoError(String)
    InvalidState(String)
    } derive(Eq,
    Debug
    )

    Fail-closed state machine errors. Whenever a protocol, certificate, record, or cryptographic error occurs, the connection queues a corresponding Fatal Alert into its outbound buffer and permanently transitions to Failed.

    ClientConfig

    Configuration for a TLCP 1.1 client connection.

    ClientConfig::new

    Creates a ClientConfig with default cipher suites, no client certs, and no resumed session.

    ClientConn

    pub struct ClientConn {
    config : ClientConfig
    prng : Prng
    state : ClientState
    read_layer :
    RecordLayer

    write_layer :
    RecordLayer

    write_encrypted : Bool
    inbound : Array[Byte]
    hs_buf : Array[Byte]
    outbound : Array[Byte]
    transcript :
    Transcript

    client_random : Bytes
    server_random : Bytes
    session_id : Bytes
    suite :
    CipherSuite
    ?
    peer_bundle :
    DualCertBundle
    ?
    server_eph_pub :
    PublicKey
    ?
    cert_requested : Bool
    master_secret : Bytes
    key_block :
    KeyBlock
    ?
    resumed : Bool
    local_closed : Bool
    peer_closed : Bool
    }

    Sans-I/O TLCP 1.1 client connection.

    ClientConn::close_notify

    fn ClientConn::close_notify(self : ClientConn) -> Bytes raise StateError

    Emits a Warning / CloseNotify alert record and marks the local write half closed.

    ClientConn::export_session

    fn ClientConn::export_session(self : ClientConn) -> ResumedSession?

    ClientConn::feed

    fn ClientConn::feed(self : ClientConn, data : BytesView) -> Array[Event] raise StateError

    Feeds arbitrary incoming TCP/transport bytes (including 1-byte trickle or coalesced multi-record buffers) into the client state machine.

    ClientConn::is_established

    fn ClientConn::is_established(self : ClientConn) -> Bool

    ClientConn::is_failed

    fn ClientConn::is_failed(self : ClientConn) -> Bool

    ClientConn::is_resumed

    fn ClientConn::is_resumed(self : ClientConn) -> Bool

    ClientConn::negotiated_suite

    ClientConn::new

    fn ClientConn::new(config : ClientConfig) -> ClientConn

    Creates a new ClientConn in the Start state.

    ClientConn::session_id

    fn ClientConn::session_id(self : ClientConn) -> Bytes

    ClientConn::start_handshake

    fn ClientConn::start_handshake(self : ClientConn) -> Bytes raise StateError

    Initiates the TLCP 1.1 handshake by encoding and returning the initial ClientHello record bytes.

    ClientConn::take_outbound

    fn ClientConn::take_outbound(self : ClientConn) -> Bytes

    Drains and returns all queued outbound wire bytes (handshake responses or Fatal Alerts emitted during feed).

    ClientConn::write_app_data

    fn ClientConn::write_app_data(self : ClientConn, data : Bytes) -> Bytes raise StateError

    Encrypts application data (automatically fragmenting into <= 16KB TLCP records) and returns the wire bytes.

    ClientState

    type ClientState derive(Eq)

    Event

    pub(all) enum Event {
    HandshakeComplete
    ApplicationData(Bytes)
    PeerClosed
    WarningAlert(
    AlertDescription
    )
    } derive(Eq,
    Debug
    )

    High-level events produced by ClientConn::feed and ServerConn::feed.

    Prng

    type Prng

    Deterministic SM3-based counter DRBG derived from caller-supplied seed.

    ResumedSession

    pub(all) struct ResumedSession {
    session_id : Bytes
    cipher_suite :
    CipherSuite

    master_secret : Bytes
    peer_certs :
    DualCertBundle
    ?
    } derive(Eq,
    Debug
    )

    Exportable TLCP session state used for Session ID resumption. Retains authenticated peer_certs (if any) so mTLCP servers never resume an unauthenticated session when require_client_cert is enabled.

    ServerConfig

    Configuration for a TLCP 1.1 server connection (GM/T 0024 dual certificates).

    ServerConfig::new

    Creates a ServerConfig with default cipher suites, optional mTLCP disabled, and no session store.

    ServerConn

    pub struct ServerConn {
    config : ServerConfig
    prng : Prng
    state : ServerState
    read_layer :
    RecordLayer

    write_layer :
    RecordLayer

    write_encrypted : Bool
    inbound : Array[Byte]
    hs_buf : Array[Byte]
    outbound : Array[Byte]
    transcript :
    Transcript

    client_random : Bytes
    server_random : Bytes
    session_id : Bytes
    suite :
    CipherSuite
    ?
    peer_bundle :
    DualCertBundle
    ?
    server_eph_priv :
    PrivateKey
    ?
    client_cert_requested : Bool
    master_secret : Bytes
    key_block :
    KeyBlock
    ?
    resumed : Bool
    local_closed : Bool
    peer_closed : Bool
    }

    Sans-I/O TLCP 1.1 server connection.

    ServerConn::close_notify

    fn ServerConn::close_notify(self : ServerConn) -> Bytes raise StateError

    Emits a Warning / CloseNotify alert record and marks the local write half closed.

    ServerConn::export_session

    fn ServerConn::export_session(self : ServerConn) -> ResumedSession?

    ServerConn::feed

    fn ServerConn::feed(self : ServerConn, data : BytesView) -> Array[Event] raise StateError

    Feeds arbitrary incoming TCP/transport bytes (including 1-byte trickle or coalesced multi-record buffers) into the server state machine.

    ServerConn::is_established

    fn ServerConn::is_established(self : ServerConn) -> Bool

    ServerConn::is_failed

    fn ServerConn::is_failed(self : ServerConn) -> Bool

    ServerConn::is_resumed

    fn ServerConn::is_resumed(self : ServerConn) -> Bool

    ServerConn::negotiated_suite

    ServerConn::new

    fn ServerConn::new(config : ServerConfig) -> ServerConn

    Creates a new ServerConn waiting for a ClientHello.

    ServerConn::session_id

    fn ServerConn::session_id(self : ServerConn) -> Bytes

    ServerConn::take_outbound

    fn ServerConn::take_outbound(self : ServerConn) -> Bytes

    Drains and returns all queued outbound wire bytes (handshake flights or Fatal Alerts emitted during feed).

    ServerConn::write_app_data

    fn ServerConn::write_app_data(self : ServerConn, data : Bytes) -> Bytes raise StateError

    Encrypts application data (automatically fragmenting into <= 16KB TLCP records) and returns the wire bytes.

    ServerState

    type ServerState derive(Eq)

    SessionStore

    pub struct SessionStore {
    entries : Array[ResumedSession]
    }

    In-memory server-side session store mapping session_id to ResumedSession.

    SessionStore::get

    fn SessionStore::get(self : SessionStore, session_id : Bytes) -> ResumedSession?

    Looks up a cached session by session_id.

    SessionStore::len

    fn SessionStore::len(self : SessionStore) -> Int

    Returns the number of cached sessions.

    SessionStore::new

    Creates an empty SessionStore.

    SessionStore::put

    fn SessionStore::put(self : SessionStore, session : ResumedSession) -> Unit

    Inserts or updates a validated session entry keyed by session.session_id. Invalid entries (session_id not in 1..=32 bytes or master_secret != 48 bytes) are ignored.

    SessionStore::remove

    fn SessionStore::remove(self : SessionStore, session_id : Bytes) -> Unit

    Removes a session entry by session_id.

    default_cipher_suites

    Returns the default ordered list of all 4 GM/T 0024-2023 cipher suites (preferring ECC with SM4-GCM AEAD first, followed by ECC-CBC and ECDHE suites).