fishlim: Use a clear enum name

💄
This commit is contained in:
BakasuraRCE
2019-05-31 21:13:32 -05:00
parent 8aac03ae10
commit 98255c5d29
4 changed files with 21 additions and 18 deletions

View File

@ -284,11 +284,11 @@ char *fish_encrypt(const char *key, size_t keylen, const char *message, size_t m
return NULL;
switch (mode) {
case CBC:
case FISH_CBC_MODE:
openssl_base64_encode((const unsigned char *) ciphertext, ciphertext_len, &b64);
break;
case ECB:
case FISH_ECB_MODE:
b64 = fish_base64_encode((const char *) ciphertext, ciphertext_len);
}
@ -310,12 +310,12 @@ char *fish_decrypt(const char *key, size_t keylen, const char *data, enum fish_m
return NULL;
switch (mode) {
case CBC:
case FISH_CBC_MODE:
if (openssl_base64_decode(data, (unsigned char **) &ciphertext, &ciphertext_len) != 0)
return NULL;
break;
case ECB:
case FISH_ECB_MODE:
ciphertext = fish_base64_decode(data, &ciphertext_len);
}
@ -357,7 +357,7 @@ char *fish_encrypt_for_nick(const char *nick, const char *data, enum fish_mode *
g_free(key);
if (encrypted == NULL || mode == ECB)
if (encrypted == NULL || mode == FISH_ECB_MODE)
return encrypted;
/* Add '*' for CBC */
@ -386,7 +386,7 @@ char *fish_decrypt_from_nick(const char *nick, const char *data, enum fish_mode
*omode = mode;
if (mode == CBC)
if (mode == FISH_CBC_MODE)
++data;
/* Decrypt */

View File

@ -30,7 +30,10 @@
#include <glib.h>
enum fish_mode {ECB = 0x1, CBC = 0x2};
enum fish_mode {
FISH_ECB_MODE = 0x1,
FISH_CBC_MODE = 0x2
};
char *fish_encrypt(const char *key, size_t keylen, const char *message, size_t message_len, enum fish_mode mode);
char *fish_decrypt(const char *key, size_t keylen, const char *data, enum fish_mode mode);

View File

@ -121,12 +121,12 @@ char *keystore_get_key(const char *nick, enum fish_mode *mode) {
g_free(escaped_nick);
/* Determine cipher mode */
*mode = ECB;
*mode = FISH_ECB_MODE;
if (key_mode) {
if (*key_mode == '1')
*mode = ECB;
*mode = FISH_ECB_MODE;
else if (*key_mode == '2')
*mode = CBC;
*mode = FISH_CBC_MODE;
g_free(key_mode);
}
@ -138,11 +138,11 @@ char *keystore_get_key(const char *nick, enum fish_mode *mode) {
encrypted = (char *) value;
encrypted += 4;
encrypted_mode = ECB;
encrypted_mode = FISH_ECB_MODE;
if (*encrypted == '*') {
++encrypted;
encrypted_mode = CBC;
encrypted_mode = FISH_CBC_MODE;
}
password = (char *) get_keystore_password();
@ -232,7 +232,7 @@ gboolean keystore_store_key(const char *nick, const char *key, enum fish_mode mo
password = get_keystore_password();
if (password) {
/* Encrypt the password */
encrypted = fish_encrypt(password, strlen(password), key, strlen(key), CBC);
encrypted = fish_encrypt(password, strlen(password), key, strlen(key), FISH_CBC_MODE);
if (!encrypted) goto end;
/* Prepend "+OK " */

View File

@ -289,7 +289,7 @@ static int handle_keyx_notice(char *word[], char *word_eol[], void *userdata) {
hexchat_context *query_ctx;
const char *prefix;
char *sender, *secret_key, *priv_key = NULL;
enum fish_mode mode = ECB;
enum fish_mode mode = FISH_ECB_MODE;
if (!*dh_message || !*dh_pubkey || strlen(dh_pubkey) != 181)
return HEXCHAT_EAT_NONE;
@ -307,14 +307,14 @@ static int handle_keyx_notice(char *word[], char *word_eol[], void *userdata) {
dh_message++; /* identify-msg */
if (g_strcmp0 (word[6], "CBC") == 0)
mode = CBC;
mode = FISH_CBC_MODE;
if (!strcmp(dh_message, "DH1080_INIT")) {
char *pub_key;
hexchat_printf(ph, "Received public key from %s (%s), sending mine...", sender, fish_modes[mode]);
if (dh1080_generate_key(&priv_key, &pub_key)) {
hexchat_commandf(ph, "quote NOTICE %s :DH1080_FINISH %s%s", sender, pub_key, (mode == CBC) ? " CBC" : "");
hexchat_commandf(ph, "quote NOTICE %s :DH1080_FINISH %s%s", sender, pub_key, (mode == FISH_CBC_MODE) ? " CBC" : "");
g_free(pub_key);
} else {
hexchat_print(ph, "Failed to generate keys");
@ -376,11 +376,11 @@ static int handle_setkey(char *word[], char *word_eol[], void *userdata) {
key = word_eol[3];
}
mode = ECB;
mode = FISH_ECB_MODE;
key_lower = g_ascii_strdown(key, -1);
if (strncmp("cbc:", key_lower, 4) == 0) {
key = key+4;
mode = CBC;
mode = FISH_CBC_MODE;
} else if (strncmp("ecb:", key_lower, 4) == 0) {
key = key+4;
}