/soc/2013/ankitkv/gobjectification: 2e1dc888240d: Refactored the...
Ankit Vani
a at nevitus.org
Sat Jun 15 11:47:02 EDT 2013
Changeset: 2e1dc888240d09cdbe05ec8227325032e5bcbd9d
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-15 20:41 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/2e1dc888240d
Description:
Refactored the libpurple core to use the GObject-based PurpleCipher
diffstat:
libpurple/cipher.c | 5 +-
libpurple/core.c | 2 -
libpurple/ntlm.c | 25 +++++------
libpurple/proxy.c | 32 ++++++-------
libpurple/util.c | 114 ++++++++++++++++++++++++----------------------------
5 files changed, 83 insertions(+), 95 deletions(-)
diffs (truncated from 376 to 300 lines):
diff --git a/libpurple/cipher.c b/libpurple/cipher.c
--- a/libpurple/cipher.c
+++ b/libpurple/cipher.c
@@ -35,6 +35,7 @@
*/
#include "internal.h"
#include "cipher.h"
+#include "debug.h"
/******************************************************************************
* Globals
@@ -312,8 +313,8 @@ purple_cipher_get_digest_size(PurpleCiph
klass = PURPLE_CIPHER_GET_CLASS(cipher);
- if(klass && klass->purple_cipher_get_digest_size)
- return klass->purple_cipher_get_digest_size(cipher);
+ if(klass && klass->get_digest_size)
+ return klass->get_digest_size(cipher);
else
purple_debug_warning("cipher", "the %s cipher does not implement the "
"get_digest_size method\n",
diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -139,7 +139,6 @@ purple_core_init(const char *ui)
purple_dbus_init();
#endif
- purple_ciphers_init();
purple_cmds_init();
/* Since plugins get probed so early we should probably initialize their
@@ -240,7 +239,6 @@ purple_core_quit(void)
purple_idle_uninit();
purple_pounces_uninit();
purple_blist_uninit();
- purple_ciphers_uninit();
purple_notify_uninit();
purple_conversations_uninit();
purple_connections_uninit();
diff --git a/libpurple/ntlm.c b/libpurple/ntlm.c
--- a/libpurple/ntlm.c
+++ b/libpurple/ntlm.c
@@ -28,8 +28,11 @@
#include "util.h"
#include "ntlm.h"
-#include "cipher.h"
#include "debug.h"
+
+#include "ciphers/des.h"
+#include "ciphers/md4.h"
+
#include <string.h>
#define NTLM_NEGOTIATE_NTLM2_KEY 0x00080000
@@ -191,13 +194,11 @@ static void
des_ecb_encrypt(const guint8 *plaintext, guint8 *result, const guint8 *key)
{
PurpleCipher *cipher;
- PurpleCipherContext *context;
- cipher = purple_ciphers_find_cipher("des");
- context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_set_key(context, key, 8);
- purple_cipher_context_encrypt(context, plaintext, 8, result, 8);
- purple_cipher_context_destroy(context);
+ cipher = purple_des_cipher_new();
+ purple_cipher_set_key(cipher, key, 8);
+ purple_cipher_encrypt(cipher, plaintext, 8, result, 8);
+ g_object_unref(cipher);
}
/*
@@ -274,7 +275,6 @@ purple_ntlm_gen_type3(const gchar *usern
unsigned char nt_hpw[21];
char nt_pw[128];
PurpleCipher *cipher;
- PurpleCipherContext *context;
char *tmp;
int idx;
gchar *ucs2le;
@@ -375,11 +375,10 @@ purple_ntlm_gen_type3(const gchar *usern
nt_pw[2 * idx + 1] = 0;
}
- cipher = purple_ciphers_find_cipher("md4");
- context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_append(context, (guint8 *)nt_pw, 2 * lennt);
- purple_cipher_context_digest(context, nt_hpw, sizeof(nt_hpw));
- purple_cipher_context_destroy(context);
+ cipher = purple_md4_cipher_new();
+ purple_cipher_append(cipher, (guint8 *)nt_pw, 2 * lennt);
+ purple_cipher_digest(cipher, nt_hpw, sizeof(nt_hpw));
+ g_object_unref(cipher);
memset(nt_hpw + 16, 0, 5);
calc_resp(nt_hpw, nonce, nt_resp);
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -32,7 +32,7 @@
#define _PURPLE_PROXY_C_
#include "internal.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
#include "debug.h"
#include "dnsquery.h"
#include "notify.h"
@@ -1681,22 +1681,20 @@ static void
hmacmd5_chap(const unsigned char * challenge, int challen, const char * passwd, unsigned char * response)
{
PurpleCipher *cipher;
- PurpleCipherContext *ctx;
int i;
unsigned char Kxoripad[65];
unsigned char Kxoropad[65];
size_t pwlen;
- cipher = purple_ciphers_find_cipher("md5");
- ctx = purple_cipher_context_new(cipher, NULL);
+ cipher = purple_md5_cipher_new();
memset(Kxoripad,0,sizeof(Kxoripad));
memset(Kxoropad,0,sizeof(Kxoropad));
pwlen=strlen(passwd);
if (pwlen>64) {
- purple_cipher_context_append(ctx, (const guchar *)passwd, strlen(passwd));
- purple_cipher_context_digest(ctx, Kxoripad, sizeof(Kxoripad));
+ purple_cipher_append(cipher, (const guchar *)passwd, strlen(passwd));
+ purple_cipher_digest(cipher, Kxoripad, sizeof(Kxoripad));
pwlen=16;
} else {
memcpy(Kxoripad, passwd, pwlen);
@@ -1708,17 +1706,17 @@ hmacmd5_chap(const unsigned char * chall
Kxoropad[i]^=0x5c;
}
- purple_cipher_context_reset(ctx, NULL);
- purple_cipher_context_append(ctx, Kxoripad, 64);
- purple_cipher_context_append(ctx, challenge, challen);
- purple_cipher_context_digest(ctx, Kxoripad, sizeof(Kxoripad));
-
- purple_cipher_context_reset(ctx, NULL);
- purple_cipher_context_append(ctx, Kxoropad, 64);
- purple_cipher_context_append(ctx, Kxoripad, 16);
- purple_cipher_context_digest(ctx, response, 16);
-
- purple_cipher_context_destroy(ctx);
+ purple_cipher_reset(cipher);
+ purple_cipher_append(cipher, Kxoripad, 64);
+ purple_cipher_append(cipher, challenge, challen);
+ purple_cipher_digest(cipher, Kxoripad, sizeof(Kxoripad));
+
+ purple_cipher_reset(cipher);
+ purple_cipher_append(cipher, Kxoropad, 64);
+ purple_cipher_append(cipher, Kxoripad, 16);
+ purple_cipher_digest(cipher, response, 16);
+
+ g_object_unref(cipher);
}
static void
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -23,7 +23,7 @@
*/
#include "internal.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
#include "conversation.h"
#include "core.h"
#include "debug.h"
@@ -4852,7 +4852,7 @@ purple_uuid_random(void)
(tmp >> 16) & 0xFFFF, g_random_int());
}
-gchar *purple_cipher_http_digest_calculate_session_key(
+gchar *purple_http_digest_calculate_session_key(
const gchar *algorithm,
const gchar *username,
const gchar *realm,
@@ -4861,7 +4861,6 @@ gchar *purple_cipher_http_digest_calcula
const gchar *client_nonce)
{
PurpleCipher *cipher;
- PurpleCipherContext *context;
gchar hash[33]; /* We only support MD5. */
g_return_val_if_fail(username != NULL, NULL);
@@ -4875,16 +4874,14 @@ gchar *purple_cipher_http_digest_calcula
g_ascii_strcasecmp(algorithm, "MD5") ||
g_ascii_strcasecmp(algorithm, "MD5-sess"), NULL);
- cipher = purple_ciphers_find_cipher("md5");
+ cipher = purple_md5_cipher_new();
g_return_val_if_fail(cipher != NULL, NULL);
- context = purple_cipher_context_new(cipher, NULL);
-
- purple_cipher_context_append(context, (guchar *)username, strlen(username));
- purple_cipher_context_append(context, (guchar *)":", 1);
- purple_cipher_context_append(context, (guchar *)realm, strlen(realm));
- purple_cipher_context_append(context, (guchar *)":", 1);
- purple_cipher_context_append(context, (guchar *)password, strlen(password));
+ purple_cipher_append(cipher, (guchar *)username, strlen(username));
+ purple_cipher_append(cipher, (guchar *)":", 1);
+ purple_cipher_append(cipher, (guchar *)realm, strlen(realm));
+ purple_cipher_append(cipher, (guchar *)":", 1);
+ purple_cipher_append(cipher, (guchar *)password, strlen(password));
if (algorithm != NULL && !g_ascii_strcasecmp(algorithm, "MD5-sess"))
{
@@ -4892,29 +4889,28 @@ gchar *purple_cipher_http_digest_calcula
if (client_nonce == NULL)
{
- purple_cipher_context_destroy(context);
+ g_object_unref(cipher);
purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.\n");
return NULL;
}
- purple_cipher_context_digest(context, digest, sizeof(digest));
- purple_cipher_context_destroy(context);
-
- context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_append(context, digest, sizeof(digest));
- purple_cipher_context_append(context, (guchar *)":", 1);
- purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce));
- purple_cipher_context_append(context, (guchar *)":", 1);
- purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce));
+ purple_cipher_digest(cipher, digest, sizeof(digest));
+
+ purple_cipher_reset(cipher);
+ purple_cipher_append(cipher, digest, sizeof(digest));
+ purple_cipher_append(cipher, (guchar *)":", 1);
+ purple_cipher_append(cipher, (guchar *)nonce, strlen(nonce));
+ purple_cipher_append(cipher, (guchar *)":", 1);
+ purple_cipher_append(cipher, (guchar *)client_nonce, strlen(client_nonce));
}
- purple_cipher_context_digest_to_str(context, hash, sizeof(hash));
- purple_cipher_context_destroy(context);
+ purple_cipher_digest_to_str(cipher, hash, sizeof(hash));
+ g_object_unref(cipher);
return g_strdup(hash);
}
-gchar *purple_cipher_http_digest_calculate_response(
+gchar *purple_http_digest_calculate_response(
const gchar *algorithm,
const gchar *method,
const gchar *digest_uri,
@@ -4926,7 +4922,6 @@ gchar *purple_cipher_http_digest_calcula
const gchar *session_key)
{
PurpleCipher *cipher;
- PurpleCipherContext *context;
static gchar hash2[33]; /* We only support MD5. */
g_return_val_if_fail(method != NULL, NULL);
@@ -4946,74 +4941,71 @@ gchar *purple_cipher_http_digest_calcula
g_ascii_strcasecmp(qop, "auth") ||
g_ascii_strcasecmp(qop, "auth-int"), NULL);
- cipher = purple_ciphers_find_cipher("md5");
+ cipher = purple_md5_cipher_new();
g_return_val_if_fail(cipher != NULL, NULL);
- context = purple_cipher_context_new(cipher, NULL);
-
- purple_cipher_context_append(context, (guchar *)method, strlen(method));
- purple_cipher_context_append(context, (guchar *)":", 1);
- purple_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri));
+ purple_cipher_append(cipher, (guchar *)method, strlen(method));
+ purple_cipher_append(cipher, (guchar *)":", 1);
+ purple_cipher_append(cipher, (guchar *)digest_uri, strlen(digest_uri));
if (qop != NULL && !g_ascii_strcasecmp(qop, "auth-int"))
{
- PurpleCipherContext *context2;
+ PurpleCipher *cipher2;
gchar entity_hash[33];
if (entity == NULL)
{
- purple_cipher_context_destroy(context);
+ g_object_unref(cipher);
purple_debug_error("cipher", "Required entity missing for auth-int digest calculation.\n");
return NULL;
}
- context2 = purple_cipher_context_new(cipher, NULL);
More information about the Commits
mailing list