diff --git a/src/ssb.c b/src/ssb.c index 3d1308c7..17e57c1a 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -25,9 +25,9 @@ #include #include -static_assert(ID_BASE64_LEN == sodium_base64_ENCODED_LEN(9 + crypto_box_PUBLICKEYBYTES, sodium_base64_VARIANT_ORIGINAL), "ID_BASE64_LEN"); -static_assert(ID_BIN_LEN == crypto_box_PUBLICKEYBYTES, "ID_BIN_LEN"); -static_assert(BLOB_ID_LEN == (sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 8), "BLOB_ID_LEN"); +static_assert(k_id_base64_len == sodium_base64_ENCODED_LEN(9 + crypto_box_PUBLICKEYBYTES, sodium_base64_VARIANT_ORIGINAL), "k_id_base64_len"); +static_assert(k_id_bin_len == crypto_box_PUBLICKEYBYTES, "k_id_bin_len"); +static_assert(k_blob_id_len == (sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 8), "k_blob_id_len"); const uint8_t k_ssb_network[] = { 0xd4, 0xa1, 0xcb, 0x88, 0xa6, 0x6f, 0x02, 0xf8, @@ -1981,7 +1981,7 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad } } - char key[ID_BASE64_LEN]; + char key[k_id_base64_len]; if (tf_ssb_id_bin_to_str(key, sizeof(key), broadcast->pub)) { tf_ssb_connections_store(ssb->connections_tracker, broadcast->host, ntohs(broadcast->addr.sin_port), key); diff --git a/src/ssb.connections.c b/src/ssb.connections.c index 5b6c42fa..4d98fab0 100644 --- a/src/ssb.connections.c +++ b/src/ssb.connections.c @@ -26,7 +26,7 @@ static void _tf_ssb_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change_t { case k_tf_ssb_change_create: { - char key[ID_BASE64_LEN]; + char key[k_id_base64_len]; if (tf_ssb_connection_get_host(connection) && *tf_ssb_connection_get_host(connection) && tf_ssb_connection_get_port(connection) && @@ -39,7 +39,7 @@ static void _tf_ssb_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change_t break; case k_tf_ssb_change_connect: { - char key[ID_BASE64_LEN]; + char key[k_id_base64_len]; if (tf_ssb_connection_get_id(connection, key, sizeof(key))) { tf_ssb_connections_set_succeeded(connections, tf_ssb_connection_get_host(connection), tf_ssb_connection_get_port(connection), key); @@ -83,10 +83,10 @@ static void _tf_ssb_connections_timer(uv_timer_t* timer) { char host[256]; int port; - char key[ID_BASE64_LEN]; + char key[k_id_base64_len]; if (_tf_ssb_connections_get_next_connection(connections, host, sizeof(host), &port, key, sizeof(key))) { - uint8_t key_bin[ID_BIN_LEN]; + uint8_t key_bin[k_id_bin_len]; if (tf_ssb_id_str_to_bin(key_bin, key)) { tf_ssb_connect(connections->ssb, host, port, key_bin); diff --git a/src/ssb.db.c b/src/ssb.db.c index edb689a5..948f609c 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -117,7 +117,7 @@ bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) { if (sqlite3_bind_int64(statement, 1, last_row_id) == SQLITE_OK && - sqlite3_bind_int(statement, 2, BLOB_ID_LEN - 1) == SQLITE_OK) + sqlite3_bind_int(statement, 2, k_blob_id_len - 1) == SQLITE_OK) { int r = SQLITE_OK; while ((r = sqlite3_step(statement)) == SQLITE_ROW) diff --git a/src/ssb.h b/src/ssb.h index 292f1a71..ab7b6377 100644 --- a/src/ssb.h +++ b/src/ssb.h @@ -5,10 +5,6 @@ #include #include -#define ID_BASE64_LEN 57 -#define ID_BIN_LEN 32 -#define BLOB_ID_LEN 53 - enum { k_ssb_rpc_flag_binary = 0x0, @@ -40,6 +36,7 @@ struct sockaddr_in; enum { k_id_base64_len = 57, k_id_bin_len = 32, + k_blob_id_len = 53, }; tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db, const char* secrets_path); diff --git a/src/task.c b/src/task.c index 0c085cb6..4ecbce73 100644 --- a/src/task.c +++ b/src/task.c @@ -1099,11 +1099,6 @@ JSValue _tf_task_sandbox_require(JSContext* context, JSValueConst this_val, int return JS_UNDEFINED; } -static JSValue _utf8Decode(JSContext* context, uint8_t* data, size_t length) -{ - return JS_NewStringLen(context, (const char*)data, length); -} - static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { JSValue result = JS_NULL; @@ -1117,7 +1112,7 @@ static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, in uint8_t* array = tf_try_get_array_buffer(context, &length, argv[0]); if (array) { - result = _utf8Decode(context, array, length); + result = JS_NewStringLen(context, (const char*)array, length); } else { @@ -1130,7 +1125,7 @@ static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, in array = tf_try_get_array_buffer(context, &size, buffer); if (array) { - result = _utf8Decode(context, array, size); + result = JS_NewStringLen(context, (const char*)array, size); } } JS_FreeValue(context, buffer);