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 overSSL_ctrlrather than exported symbols. The one that matters,SSL_set_tlsext_host_namefor SNI, is wrapped here asssl_set_sniover the realSSL_ctrlsymbol. Every extern in this file was checked againstnm -Don the shipped libraries.
Constants
const SSL_FILETYPE_PEM: i32 = 1;
const SSL_FILETYPE_ASN1: i32 = 2;
const SSL_VERIFY_NONE: i32 = 0;
const SSL_VERIFY_PEER: i32 = 1;
const SSL_VERIFY_FAIL_IF_NO_PEER_CERT: i32 = 2;
const SSL_ERROR_NONE: i32 = 0;
const SSL_ERROR_SSL: i32 = 1;
const SSL_ERROR_WANT_READ: i32 = 2;
const SSL_ERROR_WANT_WRITE: i32 = 3;
const SSL_ERROR_WANT_X509_LOOKUP: i32 = 4;
const SSL_ERROR_SYSCALL: i32 = 5;
const SSL_ERROR_ZERO_RETURN: i32 = 6;
const SSL_ERROR_WANT_CONNECT: i32 = 7;
const SSL_ERROR_WANT_ACCEPT: i32 = 8;
const X509_V_OK: i64 = 0;
const SSL_CTRL_SET_TLSEXT_HOSTNAME: i32 = 55;
const TLSEXT_NAMETYPE_host_name: i64 = 0;extern function exit(code: i32) -> void;
extern "C" {
function puts(s: string) -> i32;
}Declares a function whose body the linker supplies - typically a C library symbol. The compiler trusts the Cryo signature; keeping it in step with the real C signature is on you.
language referencefunction name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
extern "C" function OpenSSL_version_num() -> u64extern "C" function TLS_client_method() -> void*extern "C" function TLS_server_method() -> void*extern "C" function SSL_CTX_new(method: void*) -> void*(parameter) method: void*extern "C" function SSL_CTX_free(ctx: void*) -> void(parameter) ctx: void*extern "C" function SSL_new(ctx: void*) -> void*extern "C" function SSL_free(ssl: void*) -> void(parameter) ssl: void*extern "C" function SSL_set_fd(ssl: void*, fd: i32) -> i32(parameter) fd: i32extern "C" function SSL_connect(ssl: void*) -> i32extern "C" function SSL_accept(ssl: void*) -> i32extern "C" function SSL_read(ssl: void*, buf: u8*, num: i32) -> i32(parameter) buf: u8*(parameter) num: i32extern "C" function SSL_write(ssl: void*, buf: u8*, num: i32) -> i32extern "C" function SSL_shutdown(ssl: void*) -> i32extern "C" function SSL_get_error(ssl: void*, ret: i32) -> i32(parameter) ret: i32extern "C" function SSL_ctrl(ssl: void*, cmd: i32, larg: i64, parg: void*) -> i64(parameter) cmd: i32(parameter) larg: i64(parameter) parg: void*function ssl_set_sni(ssl: void*, name: u8*) -> i64Set the SNI hostname on a client SSL before the handshake. Wraps the SSL_set_tlsext_host_name header macro over the real SSL_ctrl symbol. name must be NUL-terminated. Returns 1 on success.
(parameter) name: u8*const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const SSL_FILETYPE_PEM: i32 = 1;const SSL_FILETYPE_ASN1: i32 = 2;const SSL_VERIFY_NONE: i32 = 0;const SSL_VERIFY_PEER: i32 = 1;const SSL_VERIFY_FAIL_IF_NO_PEER_CERT: i32 = 2;const SSL_ERROR_NONE: i32 = 0;const SSL_ERROR_SSL: i32 = 1;const SSL_ERROR_WANT_READ: i32 = 2;const SSL_ERROR_WANT_WRITE: i32 = 3;const SSL_ERROR_WANT_X509_LOOKUP: i32 = 4;const SSL_ERROR_SYSCALL: i32 = 5;const SSL_ERROR_ZERO_RETURN: i32 = 6;const SSL_ERROR_WANT_CONNECT: i32 = 7;const SSL_ERROR_WANT_ACCEPT: i32 = 8;const X509_V_OK: i64 = 0;const SSL_CTRL_SET_TLSEXT_HOSTNAME: i32 = 55;const TLSEXT_NAMETYPE_host_name: i64 = 0;import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::ffi::openssl;ffi::openssl: bindings to the system OpenSSL (libssl + libcrypto).
extern "C" function SSL_ctrl(ssl: void*, cmd: i32, larg: i64, parg: void*) -> i64function ssl_set_sni(ssl: void*, name: u8*) -> i64Set the SNI hostname on a client SSL before the handshake. Wraps the SSL_set_tlsext_host_name header macro over the real SSL_ctrl symbol. name must be NUL-terminated. Returns 1 on success.