Skip to content
CryoCryo home
Stdlibffi

openssl

import std::ffi::openssl; · source

The OpenSSL surface

extern "C" {
    function OpenSSL_version_num() -> u64;
    function TLS_client_method() -> void*;
    function TLS_server_method() -> void*;
    function SSL_CTX_new(method: void*) -> void*;
    function SSL_CTX_free(ctx: void*) -> void;
    function SSL_new(ctx: void*) -> void*;
    function SSL_free(ssl: void*) -> void;
    function SSL_set_fd(ssl: void*, fd: i32) -> i32;
    function SSL_connect(ssl: void*) -> i32;
    function SSL_accept(ssl: void*) -> i32;
    function SSL_read(ssl: void*, buf: u8*, num: i32) -> i32;
    function SSL_write(ssl: void*, buf: u8*, num: i32) -> i32;
    function SSL_shutdown(ssl: void*) -> i32;
    function SSL_get_error(ssl: void*, ret: i32) -> i32;
    function SSL_ctrl(ssl: void*, cmd: i32, larg: i64, parg: void*) -> i64;
    // ...
}

function ssl_set_sni(ssl: void*, name: u8*) -> i64;

Raw extern "C" declarations for the subset of the OpenSSL 3.x API that net::tls drives. Opaque handles — SSL, SSL_CTX, SSL_METHOD — cross as void*, and you own the lifetime: pair every *_new with its *_free.

A binary that pulls in net::tls must add ssl and crypto to link_libs in its cryoconfig. Nothing here is referenced unless net::tls is used, so non-TLS binaries link without OpenSSL at all.

Several "functions" in <openssl/ssl.h> are preprocessor macros over SSL_ctrl rather than exported symbols. The one that matters, SSL_set_tlsext_host_name for SNI, is wrapped here as ssl_set_sni over the real SSL_ctrl symbol. Every extern in this file was checked against nm -D on the shipped libraries.