From cf36c993ba4bb931ecf9c84de41ab0bc5fc915e4 Mon Sep 17 00:00:00 2001 From: ame Date: Wed, 13 Mar 2024 16:03:10 -0500 Subject: blake2{b,s} and maybe other stuff --- docs/crypto.md | 4 +- docs/net.md | 320 ++++++++++++++++++++++++++++----------------------------- docs/readme.md | 48 ++++----- 3 files changed, 187 insertions(+), 185 deletions(-) (limited to 'docs') diff --git a/docs/crypto.md b/docs/crypto.md index 997ede9..6a375b8 100644 --- a/docs/crypto.md +++ b/docs/crypto.md @@ -4,7 +4,7 @@ \* is optional -|name|out len|arg 2|extra| +|name|out len|other args|extra| |--|--|--|--| | sha0 | 160 | nil | insecure, use sha1| | sha1 | 160 | nil | | @@ -54,6 +54,8 @@ | spookyhash64_v2 | 64 | *seed | | | spookyhash32_v1 | 32 | *seed | | | spookyhash32_v2 | 32 | *seed | | +| blake2b | length of arg 2 * 8 | *output len (default is 64), *key | | +| blake2s | length of arg 2 * 8 | *output len (default is 32), *key | | ### usage diff --git a/docs/net.md b/docs/net.md index b4f749a..8becf4c 100644 --- a/docs/net.md +++ b/docs/net.md @@ -1,160 +1,160 @@ -# net - -## listen (PARTIALLY IMPLEMENTED) - -'takes a function with 1 argument and a integer for a port - -(intentionally styled after expressjs:3) -the function will be ran on initilization, the argument has info on the server and functions to set it up - -** -right now everything within a server:GET function is partially global, it can read global variables (by making a copy), -it can not read/copy local variables or modify globals -** - -```lua -llib.net.listen(function(server) - ... -end, 80) -``` - -### server:lock server:unlock - -continues on the current thread, but pauses all other threads at that point - -```lua -... -server:lock() ---do something with a global -server:unlock() -... -``` - -### server:close - -closes server - -### server:GET/POST/... - -'takes a string (the path) and a function to be ran in the background on request - -the function has 2 arguments, the first (res) contains functions and info about resolving the request, -the second (req) contains info on the request, the path allows for wildcards, multiple get requests per path is allowed - -the actual name of the function will change based on what request method you want to accept, all requests are treated the exact same on the backend, besides HEAD requests which will also use all GET requets, and the 'all' variant will get everything - -```lua -server:all("*", function(res, req, next) - if(req['Version'] ~= "HTTP/1.1") then - res:close() - end -end) - -... -server:GET("/", function(res, req) do - --version will always be 1.1, as per the middleware - ... -end) -... -``` - -#### res:write - -'takes a string - -sends the string to the client, constructs a header on first call (whether or not res.header._sent is null) -(the constructed header can not be changed later on in the request), and sends the string without closing the client - -```lua -... -res:write("

hello world

") -res:write("

good bye world

") -... -``` - -#### res:send - -'takes a string - -sends the string to the client, constructs a header then closes client_fd - -```lua -... -res:send("

hello world

") -... -``` - -#### res:close - -closes connection, sets res.client_fd to -1, any calls that use this value will fail - -#### res.header - -table containing all head information, anything added to it will be used, certain keys will affect other values or have other side effects on res:send, listed below - -|key|side effect| -|--|--| -|Code|Changes response note, ie: (200: OK)| - -```lua -... -res.header["Code"] = 404 -res.header["test"] = "wowa" --- new header will have a code of 404 (at the top duh) --- and a new field "test" --- --- HTTP/1.1 404 Not Found --- ... --- test: wowa -... -``` - -### res:serve ** - -'takes one string, which is a path that will be served, file or dir - -```lua -... -res:serve("./html/") -... -``` - -### req:roll - -'takes an integer of bytes to read & parse - -will update req according to how the bytes needed to be parsed, returns the number of bytes read (not necessarily parsed), 0 if there -is no more data, and any other values \< 0 is a recv error - -```lua ---when a request contains "hello world" -req.Body --"hello" -req:roll(30) --does not matter if you go over, returns 7 (probably) -req.Body --"hello world" -req:roll(50) --returns 0, no more to read ---req.Body has not been updated -``` - -can have unique results with files (this example is not perfect, roll could read less than 2 bytes, and this does not account for newlines) - -```lua ---sent a file ina request to the server, where the boundary is 'abcd': --- ---abcd --- (header junk, file name and stuff) --- --- wowa --- -- --- --ab --- --abcd - ---when the line 'wowa' has just been read, using roll for less than two will not update the file -req.Body -- (...)"wowa" -req:roll(2) -req.Body -- (...)"wowa" (unchanged) ---any lines that contain just the boundary and -'s will be put in a seperate buffer until it ends or breaks ---a previous condition, then it will be added -req:roll(2) -req.Body -- (...)"wowa\n--" ---and now "--" (from the next line) is in the possible boundary buffer, it ends in "ab" so it will be added to the main body -``` - +# net + +## listen (PARTIALLY IMPLEMENTED) + +'takes a function with 1 argument and a integer for a port + +(intentionally styled after expressjs:3) +the function will be ran on initilization, the argument has info on the server and functions to set it up + +** +right now everything within a server:GET function is partially global, it can read global variables (by making a copy), +it can not read/copy local variables or modify globals +** + +```lua +llib.net.listen(function(server) + ... +end, 80) +``` + +### server:lock server:unlock + +continues on the current thread, but pauses all other threads at that point + +```lua +... +server:lock() +--do something with a global +server:unlock() +... +``` + +### server:close + +closes server + +### server:GET/POST/... + +'takes a string (the path) and a function to be ran in the background on request + +the function has 2 arguments, the first (res) contains functions and info about resolving the request, +the second (req) contains info on the request, the path allows for wildcards, multiple get requests per path is allowed + +the actual name of the function will change based on what request method you want to accept, all requests are treated the exact same on the backend, besides HEAD requests which will also use all GET requets, and the 'all' variant will get everything + +```lua +server:all("*", function(res, req, next) + if(req['Version'] ~= "HTTP/1.1") then + res:close() + end +end) + +... +server:GET("/", function(res, req) do + --version will always be 1.1, as per the middleware + ... +end) +... +``` + +#### res:write + +'takes a string + +sends the string to the client, constructs a header on first call (whether or not res.header._sent is null) +(the constructed header can not be changed later on in the request), and sends the string without closing the client + +```lua +... +res:write("

hello world

") +res:write("

good bye world

") +... +``` + +#### res:send + +'takes a string + +sends the string to the client, constructs a header then closes client_fd + +```lua +... +res:send("

hello world

") +... +``` + +#### res:close + +closes connection, sets res.client_fd to -1, any calls that use this value will fail + +#### res.header + +table containing all head information, anything added to it will be used, certain keys will affect other values or have other side effects on res:send, listed below + +|key|side effect| +|--|--| +|Code|Changes response note, ie: (200: OK)| + +```lua +... +res.header["Code"] = 404 +res.header["test"] = "wowa" +-- new header will have a code of 404 (at the top duh) +-- and a new field "test" +-- +-- HTTP/1.1 404 Not Found +-- ... +-- test: wowa +... +``` + +### res:serve ** + +'takes one string, which is a path that will be served, file or dir + +```lua +... +res:serve("./html/") +... +``` + +### req:roll + +'takes an integer of bytes to read & parse + +will update req according to how the bytes needed to be parsed, returns the number of bytes read (not necessarily parsed), 0 if there +is no more data, and any other values \< 0 is a recv error + +```lua +--when a request contains "hello world" +req.Body --"hello" +req:roll(30) --does not matter if you go over, returns 7 (probably) +req.Body --"hello world" +req:roll(50) --returns 0, no more to read +--req.Body has not been updated +``` + +can have unique results with files (this example is not perfect, roll could read less than 2 bytes, and this does not account for newlines) + +```lua +--sent a file ina request to the server, where the boundary is 'abcd': +-- ---abcd +-- (header junk, file name and stuff) +-- +-- wowa +-- -- +-- --ab +-- --abcd + +--when the line 'wowa' has just been read, using roll for less than two will not update the file +req.Body -- (...)"wowa" +req:roll(2) +req.Body -- (...)"wowa" (unchanged) +--any lines that contain just the boundary and -'s will be put in a seperate buffer until it ends or breaks +--a previous condition, then it will be added +req:roll(2) +req.Body -- (...)"wowa\n--" +--and now "--" (from the next line) is in the possible boundary buffer, it ends in "ab" so it will be added to the main body +``` + diff --git a/docs/readme.md b/docs/readme.md index 18deebf..14859a5 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,24 +1,24 @@ -# lualib (llib) -(name subject to change) - -with the library in the same directory [(or one of the other valid search locations)](https://www.lua.org/pil/8.1.html) - -```lua -require "llib" -``` - -which makes a global llib table - -> ### future require versions will eventually return the table -> ```lua -> llib = require "llib" -> ``` - -the table has many subtables, with related function in them, you can view them like so - -```lua -llib.io.pprint(llib) --pprint is a part of the io module, pprint meaning pretty print -``` - -all subtables have a corresponding file in this directory, with info on its functions - +# lualib (llib) +(name subject to change) + +with the library in the same directory [(or one of the other valid search locations)](https://www.lua.org/pil/8.1.html) + +```lua +require "llib" +``` + +which makes a global llib table + +> ### future require versions will eventually return the table +> ```lua +> llib = require "llib" +> ``` + +the table has many subtables, with related function in them, you can view them like so + +```lua +llib.io.pprint(llib) --pprint is a part of the io module, pprint meaning pretty print +``` + +all subtables have a corresponding file in this directory, with info on its functions + -- cgit v1.2.3