# Returned from C as Ptr struct SSL_Method ptr end struct BIO_Method ptr end struct SSL_Context ptr end mutable struct SSLContext <: IO data ptr::Ptr{SSL_Context} "Construct the SSLContext object, initializing its relatvie SSL_Context pointer. Might throw ErrorException if the ccall fails" function SSLContext(; method::Ptr{SSL_Method} = TLS_method()) ssl_context = new() ssl_context.ptr = SSL_CTX_new(method) if ssl_context.ptr == C_NULL # TODO: check error stack and report the right exception throw(ErrorException("Could not create SSL context")) end ssl_context end end mutable struct SSLClient{T} rbio::Ptr{Cvoid} wbio::Ptr{Cvoid} context::SSLContext ssl::Ptr{Cvoid} io_on_read sock::T write_buf::Vector{UInt8} encrypt_buf::Vector{UInt8} function SSLClient(ctx::SSLContext, io::T) where T client = new{T}() client.context = ctx client.ssl = SSL_new(ctx) client.io_on_read = (data) -> nothing SSL_accept_state(client) set_bio!(client, bio_new(), bio_new()) client.write_buf = UInt8[] client.encrypt_buf = UInt8[] client.sock = io # finalizer(free, client) client end end