diff --git a/src/bcrypt.js.c b/src/bcrypt.js.c deleted file mode 100644 index 674dc9402..000000000 --- a/src/bcrypt.js.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "bcrypt.js.h" - -#include "task.h" - -#include "ow-crypt.h" -#include "quickjs.h" -#include "uv.h" - -static JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) -{ - const char* key = JS_ToCString(context, argv[0]); - const char* salt = JS_ToCString(context, argv[1]); - char output[7 + 22 + 31 + 1]; - char* hash = crypt_rn(key, salt, output, sizeof(output)); - JSValue result = JS_NewString(context, hash); - JS_FreeCString(context, key); - JS_FreeCString(context, salt); - return result; -} - -static JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) -{ - int length = 0; - JS_ToInt32(context, &length, argv[0]); - char buffer[16]; - tf_task_t* task = tf_task_get(context); - size_t bytes = uv_random(tf_task_get_loop(task), &(uv_random_t) { 0 }, buffer, sizeof(buffer), 0, NULL) == 0 ? sizeof(buffer) : 0; - char output[7 + 22 + 1]; - char* salt = crypt_gensalt_rn("$2b$", length, buffer, bytes, output, sizeof(output)); - JSValue result = JS_NewString(context, salt); - return result; -} - -void tf_bcrypt_register(JSContext* context) -{ - JSValue global = JS_GetGlobalObject(context); - JSValue bcrypt = JS_NewObject(context); - JS_SetPropertyStr(context, global, "bCrypt", bcrypt); - JS_SetPropertyStr(context, bcrypt, "hashpw", JS_NewCFunction(context, _crypt_hashpw, "hashpw", 2)); - JS_SetPropertyStr(context, bcrypt, "gensalt", JS_NewCFunction(context, _crypt_gensalt, "gensalt", 1)); - JS_FreeValue(context, global); -} diff --git a/src/bcrypt.js.h b/src/bcrypt.js.h deleted file mode 100644 index 259a58e22..000000000 --- a/src/bcrypt.js.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -/** -** \defgroup bcrypt_js bCrypt -** Exposes bcrypt to script, where it is used for hashing and verifying -** passwords. -** @{ -*/ - -/** A JS context. */ -typedef struct JSContext JSContext; - -/** -** Register the bcrypt script interface. -** @param context The JS context. -*/ -void tf_bcrypt_register(JSContext* context); - -/** @} */ diff --git a/src/task.c b/src/task.c index d358879aa..326be2084 100644 --- a/src/task.c +++ b/src/task.c @@ -1,7 +1,6 @@ #include "task.h" #include "api.js.h" -#include "bcrypt.js.h" #include "database.js.h" #include "file.js.h" #include "httpd.js.h" @@ -1728,7 +1727,6 @@ void tf_task_activate(tf_task_t* task) tf_trace_set_write_callback(task->_trace, _tf_task_trace_to_parent, task); } - tf_bcrypt_register(context); tf_util_register(context); JS_SetPropertyStr(context, global, "exit", JS_NewCFunction(context, _tf_task_exit, "exit", 1)); JS_SetPropertyStr(context, global, "version", JS_NewCFunction(context, _tf_task_version, "version", 0));