38 lines
918 B
Julia
38 lines
918 B
Julia
mutable struct SSLContext <: IO
|
|
data
|
|
ptr::Ptr{Cvoid}
|
|
|
|
function SSLContext()
|
|
ssl_context = new()
|
|
method = ccall((:TLS_server_method, libssl), Ptr{Cvoid}, ())
|
|
ssl_context.ptr = ccall((:SSL_CTX_new, libssl), Ptr{Cvoid}, (Ptr{Cvoid},), method)
|
|
# if ssl_context.ptr == 0
|
|
# 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
|
|
client
|
|
end
|
|
end
|