Module bio
bio module to mapping a BIO in openssl to a lua object.
Usage:
bio = require'openssl'.bio
Functions
mem ([data=nil]) | make string as bio object |
socket (fd[, support='noclose']) | make tcp bio from socket fd |
dgram (fd[, support='noclose']) | make dgram bio from socket fd |
fd (fd[, support='noclose']) | make socket or file bio with fd |
file (file[, mode='r']) | make file object with file name or path |
accept (host_port) | make tcp listen socket |
connect (host_addr[, connect=true]) | make tcp client socket |
connect (table[, connect=true]) | make tcp client socket |
filter (mode) | make base64 or buffer bio, which can append to an io BIO object |
filter (mode, md_alg) | make digest bio, which can append to an io BIO object |
filter (mode, s[, support='noclose']) | make ssl bio |
filter (mode, key, iv[, encrypt=true]) | make cipher filter bio object |
Class bio
bio:read (len) | read data from bio object |
bio:gets ([max=256]) | get line from bio object |
bio:write (data) | write data to bio object |
bio:puts (data) | put line to bio object |
bio:flush () | flush buffer of bio object |
bio:type () | get type of bio |
bio:nbio (nonblock) | set nonblock for bio object |
bio:reset () | reset bio |
bio:push (append) | push bio append to chain of bio, if want to free a chain use free_all() |
bio:pop (toremove) | remove bio from chain |
bio:get_mem () | get mem data, only support mem bio object |
bio:accept ([setup=false]) | setup ready and accept client connect |
bio:shutdown () | shutdown SSL or TCP connection |
bio:get_ssl () | get ssl object assosited with bio object |
bio:connect () | do TCP or SSL connect |
bio:handshake () | do handshake of TCP or SSL connection |
bio:fd () | get fd of bio object |
bio:fd (fd) | set fd of bio object |
bio:set_callback (callback) | set callback function of bio information |
bio:pending () | return pending length of bytes to read and write |
bio:close () | close bio |
Functions
- mem ([data=nil])
-
make string as bio object
Parameters:
- data string , it will be memory buffer data (default nil)
Returns:
-
bio
it can be input or output object
- socket (fd[, support='noclose'])
-
make tcp bio from socket fd
Parameters:
- fd number
- support flag ‘close’ or ‘noclose’ when close or gc (default 'noclose')
Returns:
- dgram (fd[, support='noclose'])
-
make dgram bio from socket fd
Parameters:
- fd number
- support flag ‘close’ or ‘noclose’ when close or gc (default 'noclose')
Returns:
- fd (fd[, support='noclose'])
-
make socket or file bio with fd
Parameters:
- fd number
- support flag ‘close’ or ‘noclose’ when close or gc (default 'noclose')
Returns:
- file (file[, mode='r'])
-
make file object with file name or path
Parameters:
Returns:
- accept (host_port)
-
make tcp listen socket
Parameters:
- host_port string address like ‘host:port’
Returns:
- connect (host_addr[, connect=true])
-
make tcp client socket
Parameters:
- host_addr string addrees like ‘host:port’
- connect boolean default connect immediately (default true)
Returns:
- connect (table[, connect=true])
-
make tcp client socket
Parameters:
- table address with hostname, ip, port filed
- connect boolean default connect immediately (default true)
Returns:
- filter (mode)
-
make base64 or buffer bio, which can append to an io BIO object
Parameters:
- mode string support ‘base64’ or ‘buffer’
Returns:
- filter (mode, md_alg)
-
make digest bio, which can append to an io BIO object
Parameters:
Returns:
- filter (mode, s[, support='noclose'])
-
make ssl bio
Parameters:
- mode string must be ‘ssl’
- s ssl
- support flag ‘close’ or ‘noclose’ when close or gc (default 'noclose')
Returns:
- filter (mode, key, iv[, encrypt=true])
-
make cipher filter bio object
Parameters:
Returns:
Class bio
openssl.bio object
- bio:read (len)
-
read data from bio object
Parameters:
- len number
Returns:
-
string
string length may be less than param len
- bio:gets ([max=256])
-
get line from bio object
Parameters:
- max number line len (default 256)
Returns:
-
string
string length may be less than param len
- bio:write (data)
-
write data to bio object
Parameters:
- data string
Returns:
-
number
length success write
- bio:puts (data)
-
put line to bio object
Parameters:
- data string
Returns:
-
number
length success write
- bio:flush ()
-
flush buffer of bio object
Returns:
-
boolean
true for success, others for fail
- bio:type ()
-
get type of bio
Returns:
- bio:nbio (nonblock)
-
set nonblock for bio object
Parameters:
- nonblock boolean
Returns:
-
boolean
result, true for success, others for fail
- bio:reset ()
- reset bio
- bio:push (append)
-
push bio append to chain of bio, if want to free a chain use free_all()
Parameters:
- append bio
Returns:
- bio:pop (toremove)
-
remove bio from chain
Parameters:
- toremove bio
- bio:get_mem ()
-
get mem data, only support mem bio object
Returns:
- bio:accept ([setup=false])
-
setup ready and accept client connect
Parameters:
- setup boolean true for setup accept bio, false or none will accept client connect (default false)
Returns:
-
boolean
result only when setup is true
Or
-
bio
accpeted bio object
- bio:shutdown ()
- shutdown SSL or TCP connection
- bio:get_ssl ()
-
get ssl object assosited with bio object
Returns:
-
ssl
- bio:connect ()
-
do TCP or SSL connect
Returns:
-
booolean
result true for success and others for fail
- bio:handshake ()
-
do handshake of TCP or SSL connection
Returns:
-
boolean
result true for success, and others for fail
- bio:fd ()
-
get fd of bio object
Returns:
-
number
- bio:fd (fd)
-
set fd of bio object
Parameters:
- fd number
Returns:
-
number
fd
- bio:set_callback (callback)
-
set callback function of bio information
Parameters:
- callback function
Returns:
-
boolean
result true for success, and others for fail
- bio:pending ()
-
return pending length of bytes to read and write
Returns:
-
number
pending of read, followed by pending of write
- bio:close ()
- close bio