clang-format the source. Not exactly how I want it, but automated is better than perfect.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4845 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-15 23:35:01 +00:00
parent c8812b1add
commit fbc3cfeda4
37 changed files with 3141 additions and 1764 deletions

View File

@ -94,8 +94,7 @@ static JSValue _tf_ssb_addIdentity(JSContext* context, JSValueConst this_val, in
unsigned char seed[crypto_sign_SEEDBYTES];
uint8_t secret_key[crypto_sign_SECRETKEYBYTES] = { 0 };
memcpy(secret_key, array, sizeof(secret_key) / 2);
if (crypto_sign_ed25519_sk_to_seed(seed, secret_key) == 0 &&
crypto_sign_seed_keypair(public_key, secret_key, seed) == 0)
if (crypto_sign_ed25519_sk_to_seed(seed, secret_key) == 0 && crypto_sign_seed_keypair(public_key, secret_key, seed) == 0)
{
char public_key_b64[512];
tf_base64_encode(public_key, sizeof(public_key), public_key_b64, sizeof(public_key_b64));
@ -170,8 +169,7 @@ static JSValue _set_server_following_internal(tf_ssb_t* ssb, JSValueConst this_v
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "contact"));
JS_SetPropertyStr(context, message, "contact", JS_DupValue(context, id));
JS_SetPropertyStr(context, message, "following", JS_DupValue(context, following));
JSValue args[] =
{
JSValue args[] = {
server_user,
server_id,
message,
@ -246,8 +244,7 @@ static JSValue _tf_ssb_getIdentities(JSContext* context, JSValueConst this_val,
if (ssb)
{
const char* user = JS_ToCString(context, argv[0]);
identities_visit_t state =
{
identities_visit_t state = {
.context = context,
.array = result,
};
@ -294,8 +291,7 @@ static JSValue _tf_ssb_getAllIdentities(JSContext* context, JSValueConst this_va
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
if (ssb)
{
identities_visit_t state =
{
identities_visit_t state = {
.context = context,
.array = result,
};
@ -747,8 +743,7 @@ static void _tf_ssb_sqlAsync_handle_close(uv_handle_t* handle)
{
sql_work_t* work = handle->data;
handle->data = NULL;
if (!work->async.data &&
!work->timeout.data)
if (!work->async.data && !work->timeout.data)
{
tf_free(work);
}
@ -1153,8 +1148,7 @@ static void _tf_ssb_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change
case k_tf_ssb_change_connect:
{
JSValue object = JS_DupValue(context, tf_ssb_connection_get_object(connection));
JSValue args[] =
{
JSValue args[] = {
JS_NewString(context, "add"),
object,
};
@ -1170,8 +1164,7 @@ static void _tf_ssb_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change
case k_tf_ssb_change_remove:
{
JSValue object = JS_DupValue(context, tf_ssb_connection_get_object(connection));
JSValue args[] =
{
JSValue args[] = {
JS_NewString(context, "remove"),
object,
};
@ -1394,7 +1387,10 @@ static JSValue _tf_ssb_createTunnel(JSContext* context, JSValueConst this_val, i
return result;
}
enum { k_max_private_message_recipients = 8 };
enum
{
k_max_private_message_recipients = 8
};
static bool _tf_ssb_get_private_key_curve25519(sqlite3* db, const char* user, const char* identity, uint8_t out_private_key[static crypto_sign_SECRETKEYBYTES])
{
@ -1409,16 +1405,13 @@ static bool _tf_ssb_get_private_key_curve25519(sqlite3* db, const char* user, co
if (sqlite3_prepare(db, "SELECT private_key FROM identities WHERE user = ? AND public_key = ?", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 2, *identity == '@' ? identity + 1 : identity, -1, NULL) == SQLITE_OK)
sqlite3_bind_text(statement, 2, *identity == '@' ? identity + 1 : identity, -1, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
uint8_t key[crypto_sign_SECRETKEYBYTES] = { 0 };
int length = tf_base64_decode(
(const char*)sqlite3_column_text(statement, 0),
sqlite3_column_bytes(statement, 0) - strlen(".ed25519"),
key,
sizeof(key));
int length =
tf_base64_decode((const char*)sqlite3_column_text(statement, 0), sqlite3_column_bytes(statement, 0) - strlen(".ed25519"), key, sizeof(key));
if (length == crypto_sign_SECRETKEYBYTES)
{
success = crypto_sign_ed25519_sk_to_curve25519(out_private_key, key) == 0;
@ -1489,10 +1482,8 @@ static JSValue _tf_ssb_private_message_encrypt(JSContext* context, JSValueConst
length_and_key[0] = (uint8_t)recipient_count;
memcpy(length_and_key + 1, body_key, sizeof(body_key));
size_t payload_size = sizeof(nonce) +
sizeof(public_key) +
(crypto_secretbox_MACBYTES + sizeof(length_and_key)) * recipient_count +
crypto_secretbox_MACBYTES + message_size;
size_t payload_size =
sizeof(nonce) + sizeof(public_key) + (crypto_secretbox_MACBYTES + sizeof(length_and_key)) * recipient_count + crypto_secretbox_MACBYTES + message_size;
uint8_t* payload = tf_malloc(payload_size);
@ -1554,7 +1545,6 @@ static JSValue _tf_ssb_private_message_encrypt(JSContext* context, JSValueConst
JS_FreeCString(context, signer_identity);
JS_FreeCString(context, message);
return result;
}
static JSValue _tf_ssb_private_message_decrypt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
@ -1583,8 +1573,12 @@ static JSValue _tf_ssb_private_message_decrypt(JSContext* context, JSValueConst
uint8_t shared_secret[crypto_secretbox_KEYBYTES] = { 0 };
if (crypto_scalarmult(shared_secret, private_key, public_key) == 0)
{
enum { k_recipient_header_bytes = crypto_secretbox_MACBYTES + sizeof(uint8_t) + crypto_secretbox_KEYBYTES };
for (uint8_t* p = decoded + crypto_box_NONCEBYTES + crypto_secretbox_KEYBYTES; p <= decoded + decoded_length - k_recipient_header_bytes; p += k_recipient_header_bytes)
enum
{
k_recipient_header_bytes = crypto_secretbox_MACBYTES + sizeof(uint8_t) + crypto_secretbox_KEYBYTES
};
for (uint8_t* p = decoded + crypto_box_NONCEBYTES + crypto_secretbox_KEYBYTES; p <= decoded + decoded_length - k_recipient_header_bytes;
p += k_recipient_header_bytes)
{
uint8_t out[k_recipient_header_bytes] = { 0 };
int opened = crypto_secretbox_open_easy(out, p, k_recipient_header_bytes, nonce, shared_secret);
@ -1737,8 +1731,7 @@ static JSValue _tf_ssb_following(JSContext* context, JSValueConst this_val, int
void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
{
JS_NewClassID(&_tf_ssb_classId);
JSClassDef def =
{
JSClassDef def = {
.class_name = "ssb",
};
if (JS_NewClass(JS_GetRuntime(context), _tf_ssb_classId, &def) != 0)