class OpenSSL::GETS_BIO

Defined in:

openssl_ext/bio/bio.cr

Constant Summary

BIO_C_FILE_SEEK = 128
BIO_C_FILE_TELL = 133
GETS_BIO = begin bio_id = LibCrypto.BIO_get_new_index if bio_id == -1 raise(OpenSSL::Error.new("BIO_get_new_index")) end bio_type = (bio_id | LibCrypto::BIO_TYPE_SOURCE_SINK) | LibCrypto::BIO_TYPE_DESCRIPTOR biom = LibCrypto.BIO_meth_new(bio_type, "Crystal GETS BIO") if biom.null? raise(OpenSSL::Error.new("BIO_meth_new")) end {% if LibCrypto.has_method?(:BIO_meth_set_read_ex) %} LibCrypto.BIO_meth_set_read_ex(biom, ->OpenSSL::BIO.read_ex(LibCrypto::Bio*, UInt8*, LibC::SizeT, LibC::SizeT*)) {% else %}{% if OpenSSL::BIO.has_method?(:read) %} LibCrypto.BIO_meth_set_read(biom, ->OpenSSL::BIO.read(LibCrypto::Bio*, UInt8*, LibC::Int)) {% else %} LibCrypto.BIO_meth_set_read(biom, ->OpenSSL::GETS_BIO.read(LibCrypto::Bio*, LibC::Char*, LibC::Int)) {% end %}{% end %} {% if LibCrypto.has_method?(:BIO_meth_set_write_ex) %} LibCrypto.BIO_meth_set_write_ex(biom, ->OpenSSL::BIO.write_ex(LibCrypto::Bio*, UInt8*, LibC::SizeT, LibC::SizeT*)) {% else %}{% if OpenSSL::BIO.has_method?(:write) %} LibCrypto.BIO_meth_set_write(biom, ->OpenSSL::BIO.write(LibCrypto::Bio*, UInt8*, LibC::Int)) {% else %} LibCrypto.BIO_meth_set_write(biom, ->OpenSSL::GETS_BIO.write(LibCrypto::Bio*, LibC::Char*, LibC::Int)) {% end %}{% end %} {% if OpenSSL::BIO.has_method?(:create) %} LibCrypto.BIO_meth_set_create(biom, ->OpenSSL::BIO.create(LibCrypto::Bio*)) LibCrypto.BIO_meth_set_destroy(biom, ->OpenSSL::BIO.destroy(LibCrypto::Bio*)) {% else %} LibCrypto.BIO_meth_set_create(biom, ->OpenSSL::GETS_BIO.create(LibCrypto::Bio*)) LibCrypto.BIO_meth_set_destroy(biom, ->OpenSSL::GETS_BIO.destroy(LibCrypto::Bio*)) {% end %} ctrl = Proc(::Pointer(LibCrypto::Bio), LibC::Int, LibC::Long, ::Pointer(Void), LibC::Long).new do |bio, cmd, _num, _ptr| io = io_for(bio) val = {% if true %} case cmd when LibCrypto::CTRL_FLUSH io.flush 1 when LibCrypto::CTRL_PUSH, LibCrypto::CTRL_POP, LibCrypto::CTRL_EOF 0 when BIO_C_FILE_TELL, BIO_C_FILE_SEEK 0 {% if LibCrypto.has_constant?(:CTRL_SET_KTLS) %} when LibCrypto::CTRL_SET_KTLS 0 {% else %}{% if LibCrypto.has_constant?(:CTRL_SET_KTLS_SEND) %} when LibCrypto::CTRL_SET_KTLS_SEND 0 {% end %}{% end %} {% if (LibCrypto.has_constant?(:CTRL_GET_KTLS_SEND)) && (LibCrypto.has_constant?(:CTRL_GET_KTLS_RECV)) %} when LibCrypto::CTRL_GET_KTLS_SEND, LibCrypto::CTRL_GET_KTLS_RECV 0 {% end %} {% if (LibCrypto.has_constant?(:CTRL_SET_KTLS_TX_SEND_CTRL_MSG)) && (LibCrypto.has_constant?(:CTRL_CLEAR_KTLS_TX_CTRL_MSG)) %} when LibCrypto::CTRL_SET_KTLS_TX_SEND_CTRL_MSG, LibCrypto::CTRL_CLEAR_KTLS_TX_CTRL_MSG 0 {% end %} {% if LibCrypto.has_constant?(:CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE) %} when LibCrypto::CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE 0 {% end %} else STDERR.puts "WARNING: Unsupported BIO ctrl call (#{cmd})" 0 end {% end %} LibCrypto::Long.new(val) end bgets = Proc(::Pointer(LibCrypto::Bio), ::Pointer(LibC::Char), LibC::Int, LibC::Int).new do |bio, buffer, len| io = io_for(bio) io.flush position = io.pos line = io.gets(len, false) if line.nil? 0 else io.seek(position) bytes = (io.read(Slice.new(buffer, line.bytesize))).to_i if bytes == 1 else bytes = bytes - 1 end bytes end end {% if (compare_versions(LibCrypto::OPENSSL_VERSION, "1.1.0")) >= 0 %} LibCrypto.BIO_meth_set_ctrl(biom, ctrl) LibCrypto.BIO_meth_set_gets(biom, bgets) {% else %} biom.value.ctrl = ctrl biom.value.bgets = bgets {% end %} biom end

own BIO_METHOD, do not touch stdlib CRYSTAL_BIO. mutating the shared one breaks every SSL socket on crystal 1.20. we copy stdlib read/write/create/destroy and set our own ctrl+gets.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(io : IO) #

[View source]

Class Method Detail

def self.create(bio : Pointer(LibCrypto::Bio)) : LibC::Int #

[View source]
def self.destroy(bio : Pointer(LibCrypto::Bio)) : LibC::Int #

[View source]
def self.read(bio : Pointer(LibCrypto::Bio), buffer : Pointer(LibC::Char), len : LibC::Int) : LibC::Int #

[View source]
def self.write(bio : Pointer(LibCrypto::Bio), data : Pointer(LibC::Char), len : LibC::Int) : LibC::Int #

[View source]

Instance Method Detail

def finalize #

[View source]
def io : IO #

[View source]
def to_unsafe : Pointer(LibCrypto::Bio) #

[View source]