aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorame <[email protected]>2023-12-04 01:04:57 -0600
committerame <[email protected]>2023-12-04 01:04:57 -0600
commit7832bc32b4933696e7a34b180bbba46b0c98b858 (patch)
tree054f19eb9afeb242539cdf17bbed77898220c0cc
parentb224d2f0b9b344a08c6c508d61f15bdf205464f8 (diff)
crypto stuff and (some) file io
-rw-r--r--e.lua4
-rw-r--r--io.lua2
-rw-r--r--src/crypto.h70
-rw-r--r--src/io.c35
-rw-r--r--src/io.h8
-rw-r--r--src/reg.c5
-rw-r--r--tests/hash.lua2
7 files changed, 70 insertions, 56 deletions
diff --git a/e.lua b/e.lua
index 20ed603..7860474 100644
--- a/e.lua
+++ b/e.lua
@@ -1,5 +1,3 @@
require "llib"
-local wow = llib.crypto.uuencode("wowa wowa wowa WQHOIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
-print(wow)
-print(llib.crypto.uudecode(wow))
+print(llib.crypto.sha512_t("meow",224))
diff --git a/io.lua b/io.lua
new file mode 100644
index 0000000..fd58bab
--- /dev/null
+++ b/io.lua
@@ -0,0 +1,2 @@
+require "llib"
+print(llib.io.readfile("../personal-site/src/window-utils.js"))
diff --git a/src/crypto.h b/src/crypto.h
index 79be3df..fc1101e 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -36,58 +36,24 @@ uint64_t i_rr64(uint64_t, uint64_t);
static const luaL_Reg crypto_function_list [] = {
- {"md5",l_md5},
- {"sha0",l_sha0},
- {"sha1",l_sha1},
- {"sha256",l_sha256},
- {"sha224",l_sha224},
- {"setpearson",l_setpearson},
- {"pearson",l_pearson},
- {"xxh64",l_xxh64},
- {"xxh32",l_xxh32},
- {"adler32",l_adler32},
- {"bsdchecksum",l_bsdchecksum},
- {"crc8",l_crc8},
- {"crc16",l_crc16},
- {"crc32",l_crc32},
- {"fletcher8",l_fletcher8},
- {"fletcher16",l_fletcher16},
- {"fletcher32",l_fletcher32},
- {"sysvchecksum",l_sysvchecksum},
- {"xor8",l_xor8},
- {"setbuzhash",l_setbuzhash},
- {"buzhash8",l_buzhash8},
- {"buzhash16",l_buzhash16},
- {"cityhash32", l_cityhash32},
- {"cityhash64", l_cityhash64},
- {"cityhash128", l_cityhash128},
- {"djb2", l_djb2},
- {"farmhash32", l_farmhash32},
- {"farmhash64", l_farmhash64},
- {"fasthash32", l_fasthash32},
- {"fasthash64", l_fasthash64},
- {"fnv_0", l_fnv_0},
- {"fnv_1", l_fnv_1},
- {"fnv_a", l_fnv_a},
- {"oaat", l_oaat},
- {"loselose", l_loselose},
- {"metrohash64_v1", l_metrohash64_v1},
- {"metrohash64_v2", l_metrohash64_v2},
- {"metrohash128_v1", l_metrohash128_v1},
- {"metrohash128_v2", l_metrohash128_v2},
- {"murmur1_32", l_murmur1_32},
- {"murmur2_32", l_murmur2_32},
- {"pjw", l_pjw},
- {"sdbm", l_sdbm},
- {"sha512", l_sha512},
- {"sha384", l_sha384},
- {"sha512_t", l_sha512_t},
- {"spookyhash128_v1", l_spookyhash128_v1},
- {"spookyhash128_v2", l_spookyhash128_v2},
- {"spookyhash64_v1", l_spookyhash64_v1},
- {"spookyhash64_v2", l_spookyhash64_v2},
- {"spookyhash32_v1", l_spookyhash32_v1},
- {"spookyhash32_v2", l_spookyhash32_v2},
+ {"sha0",l_sha0}, {"sha1",l_sha1}, {"sha256",l_sha256}, {"sha224",l_sha224},
+ {"setpearson",l_setpearson}, {"pearson",l_pearson}, {"xxh64",l_xxh64},
+ {"xxh32",l_xxh32}, {"adler32",l_adler32}, {"bsdchecksum",l_bsdchecksum},
+ {"crc8",l_crc8}, {"crc16",l_crc16}, {"crc32",l_crc32}, {"fletcher8",l_fletcher8},
+ {"fletcher16",l_fletcher16}, {"fletcher32",l_fletcher32},
+ {"sysvchecksum",l_sysvchecksum}, {"xor8",l_xor8}, {"setbuzhash",l_setbuzhash},
+ {"buzhash8",l_buzhash8}, {"buzhash16",l_buzhash16}, {"cityhash32", l_cityhash32},
+ {"cityhash64", l_cityhash64}, {"cityhash128", l_cityhash128}, {"md5",l_md5},
+ {"djb2", l_djb2}, {"farmhash32", l_farmhash32}, {"farmhash64", l_farmhash64},
+ {"fasthash32", l_fasthash32}, {"fasthash64", l_fasthash64}, {"fnv_0", l_fnv_0},
+ {"fnv_1", l_fnv_1}, {"fnv_a", l_fnv_a}, {"oaat", l_oaat}, {"loselose", l_loselose},
+ {"metrohash64_v1", l_metrohash64_v1}, {"metrohash64_v2", l_metrohash64_v2},
+ {"metrohash128_v1", l_metrohash128_v1}, {"metrohash128_v2", l_metrohash128_v2},
+ {"murmur1_32", l_murmur1_32}, {"murmur2_32", l_murmur2_32}, {"pjw", l_pjw},
+ {"sdbm", l_sdbm}, {"sha512", l_sha512}, {"sha384", l_sha384}, {"sha512_t", l_sha512_t},
+ {"spookyhash128_v1", l_spookyhash128_v1}, {"spookyhash128_v2", l_spookyhash128_v2},
+ {"spookyhash64_v1", l_spookyhash64_v1}, {"spookyhash64_v2", l_spookyhash64_v2},
+ {"spookyhash32_v1", l_spookyhash32_v1}, {"spookyhash32_v2", l_spookyhash32_v2},
diff --git a/src/io.c b/src/io.c
new file mode 100644
index 0000000..f2a5c82
--- /dev/null
+++ b/src/io.c
@@ -0,0 +1,35 @@
+#include "io.h"
+#include "stdlib.h"
+#include "stdio.h"
+#include "string.h"
+#include "stdint.h"
+#include "unistd.h"
+
+int l_readfile(lua_State* L){
+ size_t len;
+ char* a = (char*)luaL_checklstring(L, 1, &len);
+
+ FILE *fp;
+ const uint64_t chunk_iter = 512;
+ uint64_t chunk = 512;
+ uint64_t count = 0;
+ char* out = malloc(chunk);
+
+ fp = fopen(a, "r");
+
+ for(;;){
+ char ch = fgetc(fp);
+ if(ch==EOF) break;
+
+ if(count > chunk){
+ chunk += chunk_iter;
+ out = realloc(out, chunk);
+ }
+ out[count] = ch;
+ count++;
+ }
+ lua_pushstring(L, out);
+
+ free(out);
+ return 1;
+};
diff --git a/src/io.h b/src/io.h
new file mode 100644
index 0000000..ccfe5cc
--- /dev/null
+++ b/src/io.h
@@ -0,0 +1,8 @@
+#include "lua.h"
+
+int l_readfile(lua_State*);
+
+static const luaL_Reg io_function_list [] = {
+ {"readfile",l_readfile},
+ {NULL,NULL}
+};
diff --git a/src/reg.c b/src/reg.c
index cdc6267..50dc8b9 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -1,6 +1,7 @@
#include "lua.h"
#include "table.h"
#include "crypto.h"
+#include "io.h"
int luaopen_llib(lua_State* L) {
lua_newtable(L);
@@ -13,6 +14,10 @@ int luaopen_llib(lua_State* L) {
lua_newtable(L);
luaL_register(L, NULL, crypto_function_list);
lua_setfield(L, 2, "crypto");
+
+ lua_newtable(L);
+ luaL_register(L, NULL, io_function_list);
+ lua_setfield(L, 2, "io");
//make llib global
lua_setglobal(L, "llib");
return 1;
diff --git a/tests/hash.lua b/tests/hash.lua
index e26802c..5f9d523 100644
--- a/tests/hash.lua
+++ b/tests/hash.lua
@@ -5,7 +5,7 @@ function test(name,b,exp)
if not (hash == exp) then
print(name.." not working, got "..hash.." wanted "..exp)
else
- --print(name.." was correct, "..hash)
+ print(name.." was correct, "..hash)
end
end