/soc/2013/ankitkv/gobjectification: ea5103f66b0e: Refactor the c...
Ankit Vani
a at nevitus.org
Sat Jun 15 20:29:56 EDT 2013
Changeset: ea5103f66b0ef3f6fb273aa85493c8bdb8b88016
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-16 05:59 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/ea5103f66b0e
Description:
Refactor the codebase to use PurpleHash
diffstat:
libpurple/ciphers/hmaccipher.c | 4 +-
libpurple/ciphers/pbkdf2cipher.c | 4 +-
libpurple/hash.c | 29 ----
libpurple/ntlm.c | 14 +-
libpurple/plugins/Makefile.am | 2 +-
libpurple/plugins/ciphertest.c | 160 ++++----------------------
libpurple/plugins/keyrings/internalkeyring.c | 11 +-
libpurple/plugins/perl/common/Cipher.xs | 4 -
libpurple/plugins/perl/common/Hash.xs | 90 +++++++++++++++
libpurple/plugins/perl/common/MANIFEST | 1 +
libpurple/plugins/perl/common/Makefile.mingw | 1 +
libpurple/plugins/perl/common/module.h | 4 +
libpurple/plugins/perl/common/typemap | 4 +-
libpurple/plugins/signals-test.c | 16 --
libpurple/protocols/bonjour/bonjour_ft.c | 10 +-
libpurple/protocols/gg/oauth/oauth.c | 9 +-
libpurple/protocols/jabber/auth.c | 9 +-
libpurple/protocols/jabber/auth_digest_md5.c | 30 ++--
libpurple/protocols/jabber/auth_scram.c | 18 +-
libpurple/protocols/jabber/auth_scram.h | 4 +-
libpurple/protocols/jabber/caps.c | 34 ++--
libpurple/protocols/jabber/caps.h | 4 +-
libpurple/protocols/jabber/jutil.c | 18 +-
libpurple/protocols/msn/directconn.c | 10 +-
libpurple/protocols/msn/msnutils.c | 14 +-
libpurple/protocols/msn/nexus.c | 32 ++--
libpurple/protocols/msn/notification.c | 12 +-
libpurple/protocols/msn/object.c | 18 +-
libpurple/protocols/myspace/myspace.c | 16 +-
libpurple/protocols/myspace/myspace.h | 4 +-
libpurple/protocols/oscar/clientlogin.c | 9 +-
libpurple/protocols/oscar/family_auth.c | 36 +++---
libpurple/protocols/oscar/family_oservice.c | 22 +-
libpurple/protocols/oscar/oscar.c | 12 +-
libpurple/protocols/yahoo/libymsg.c | 12 +-
libpurple/proxy.c | 32 ++--
libpurple/tests/test_cipher.c | 64 +++++-----
libpurple/tests/test_jabber_caps.c | 10 +-
libpurple/tests/test_jabber_scram.c | 4 +-
libpurple/util.c | 122 ++++++++++----------
40 files changed, 426 insertions(+), 483 deletions(-)
diffs (truncated from 2060 to 300 lines):
diff --git a/libpurple/ciphers/hmaccipher.c b/libpurple/ciphers/hmaccipher.c
--- a/libpurple/ciphers/hmaccipher.c
+++ b/libpurple/ciphers/hmaccipher.c
@@ -54,7 +54,7 @@ static GObjectClass *parent_class = NULL
******************************************************************************/
static void
purple_hmac_cipher_set_hash(PurpleCipher *cipher,
- PurpleCipher *hash)
+ PurpleHash *hash)
{
PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
@@ -295,7 +295,7 @@ purple_hmac_cipher_class_init(PurpleHMAC
cipher_class->get_block_size = purple_hmac_cipher_get_block_size;
cipher_class->get_name = purple_hmac_cipher_get_name;
- pspec = g_param_spec_object("hash", "hash", "hash", PURPLE_TYPE_CIPHER,
+ pspec = g_param_spec_object("hash", "hash", "hash", PURPLE_TYPE_HASH,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(obj_class, PROP_HASH, pspec);
}
diff --git a/libpurple/ciphers/pbkdf2cipher.c b/libpurple/ciphers/pbkdf2cipher.c
--- a/libpurple/ciphers/pbkdf2cipher.c
+++ b/libpurple/ciphers/pbkdf2cipher.c
@@ -67,7 +67,7 @@ static GObjectClass *parent_class = NULL
******************************************************************************/
static void
purple_pbkdf2_cipher_set_hash(PurpleCipher *cipher,
- PurpleCipher *hash)
+ PurpleHash *hash)
{
PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher);
@@ -344,7 +344,7 @@ purple_pbkdf2_cipher_class_init(PurplePB
cipher_class->set_key = purple_pbkdf2_cipher_set_key;
cipher_class->get_name = purple_pbkdf2_cipher_get_name;
- pspec = g_param_spec_object("hash", "hash", "hash", PURPLE_TYPE_CIPHER,
+ pspec = g_param_spec_object("hash", "hash", "hash", PURPLE_TYPE_HASH,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(obj_class, PROP_HASH, pspec);
diff --git a/libpurple/hash.c b/libpurple/hash.c
--- a/libpurple/hash.c
+++ b/libpurple/hash.c
@@ -29,7 +29,6 @@ static void
purple_hash_class_init(PurpleHashClass *klass) {
klass->reset = NULL;
klass->reset_state = NULL;
- klass->set_iv = NULL;
klass->append = NULL;
klass->digest = NULL;
klass->get_digest_size = NULL;
@@ -127,34 +126,6 @@ purple_hash_reset_state(PurpleHash *hash
}
/**
- * purple_hash_set_iv:
- * @hash: The hash to set the IV to
- * @iv: The initialization vector to set
- * @len: The len of the IV
- *
- * @note This should only be called right after a hash is created or reset
- *
- * Sets the initialization vector for a hash
- */
-void
-purple_hash_set_iv(PurpleHash *hash, guchar *iv, size_t len)
-{
- PurpleHashClass *klass = NULL;
-
- g_return_if_fail(PURPLE_IS_HASH(hash));
- g_return_if_fail(iv);
-
- klass = PURPLE_HASH_GET_CLASS(hash);
-
- if(klass && klass->set_iv)
- klass->set_iv(hash, iv, len);
- else
- purple_debug_warning("hash", "the %s hash does not implement the "
- "set_iv method\n",
- klass->get_name ? klass->get_name(hash) : "");
-}
-
-/**
* purple_hash_append:
* @hash: The hash to append data to
* @data: The data to append
diff --git a/libpurple/ntlm.c b/libpurple/ntlm.c
--- a/libpurple/ntlm.c
+++ b/libpurple/ntlm.c
@@ -30,8 +30,8 @@
#include "ntlm.h"
#include "debug.h"
-#include "ciphers/des.h"
-#include "ciphers/md4.h"
+#include "ciphers/descipher.h"
+#include "ciphers/md4hash.h"
#include <string.h>
@@ -274,7 +274,7 @@ purple_ntlm_gen_type3(const gchar *usern
unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
unsigned char nt_hpw[21];
char nt_pw[128];
- PurpleCipher *cipher;
+ PurpleHash *hash;
char *tmp;
int idx;
gchar *ucs2le;
@@ -375,10 +375,10 @@ purple_ntlm_gen_type3(const gchar *usern
nt_pw[2 * idx + 1] = 0;
}
- 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);
+ hash = purple_md4_hash_new();
+ purple_hash_append(hash, (guint8 *)nt_pw, 2 * lennt);
+ purple_hash_digest(hash, nt_hpw, sizeof(nt_hpw));
+ g_object_unref(hash);
memset(nt_hpw + 16, 0, 5);
calc_resp(nt_hpw, nonce, nt_resp);
diff --git a/libpurple/plugins/Makefile.am b/libpurple/plugins/Makefile.am
--- a/libpurple/plugins/Makefile.am
+++ b/libpurple/plugins/Makefile.am
@@ -50,6 +50,7 @@ dbus_example_la_LDFLAGS = -module -a
if PLUGINS
plugin_LTLIBRARIES = \
+ ciphertest.la \
autoaccept.la \
buddynote.la \
idle.la \
@@ -62,7 +63,6 @@ plugin_LTLIBRARIES = \
$(DBUS_LTLIB)
noinst_LTLIBRARIES = \
- ciphertest.la \
codeinline.la \
debug_example.la \
helloworld.la \
diff --git a/libpurple/plugins/ciphertest.c b/libpurple/plugins/ciphertest.c
--- a/libpurple/plugins/ciphertest.c
+++ b/libpurple/plugins/ciphertest.c
@@ -37,11 +37,11 @@
#include "version.h"
#include "util.h"
-#include "ciphers/aes.h"
-#include "ciphers/md5.h"
-#include "ciphers/pbkdf2.h"
-#include "ciphers/sha1.h"
-#include "ciphers/sha256.h"
+#include "ciphers/aescipher.h"
+#include "ciphers/md5hash.h"
+#include "ciphers/pbkdf2cipher.h"
+#include "ciphers/sha1hash.h"
+#include "ciphers/sha256hash.h"
struct test {
const gchar *question;
@@ -68,13 +68,13 @@ struct test md5_tests[8] = {
static void
cipher_test_md5(void) {
- PurpleCipher *cipher;
+ PurpleHash *hash;
gchar digest[33];
gboolean ret;
gint i = 0;
- cipher = purple_md5_cipher_new();
- if(!cipher) {
+ hash = purple_md5_hash_new();
+ if(!hash) {
purple_debug_info("cipher-test",
"could not find md5 cipher, not testing\n");
return;
@@ -86,10 +86,10 @@ cipher_test_md5(void) {
purple_debug_info("cipher-test", "Test %02d:\n", i);
purple_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question);
- purple_cipher_append(cipher, (guchar *)md5_tests[i].question,
+ purple_hash_append(hash, (guchar *)md5_tests[i].question,
strlen(md5_tests[i].question));
- ret = purple_cipher_digest_to_str(cipher, digest, sizeof(digest));
+ ret = purple_hash_digest_to_str(hash, digest, sizeof(digest));
if(!ret) {
purple_debug_info("cipher-test", "failed\n");
@@ -99,11 +99,11 @@ cipher_test_md5(void) {
md5_tests[i].answer);
}
- purple_cipher_reset(cipher);
+ purple_hash_reset(hash);
i++;
}
- g_object_unref(cipher);
+ g_object_unref(hash);
purple_debug_info("cipher-test", "md5 tests completed\n\n");
}
@@ -121,13 +121,13 @@ struct test sha1_tests[5] = {
static void
cipher_test_sha1(void) {
- PurpleCipher *cipher;
+ PurpleHash *hash;
gchar digest[41];
gint i = 0;
gboolean ret;
- cipher = purple_sha1_cipher_new();
- if(!cipher) {
+ hash = purple_sha1_hash_new();
+ if(!hash) {
purple_debug_info("cipher-test",
"could not find sha1 cipher, not testing\n");
return;
@@ -142,7 +142,7 @@ cipher_test_sha1(void) {
sha1_tests[i].question : "'a'x1000, 1000 times");
if(sha1_tests[i].question) {
- purple_cipher_append(cipher, (guchar *)sha1_tests[i].question,
+ purple_hash_append(hash, (guchar *)sha1_tests[i].question,
strlen(sha1_tests[i].question));
} else {
gint j;
@@ -151,10 +151,10 @@ cipher_test_sha1(void) {
memset(buff, 'a', 1000);
for(j = 0; j < 1000; j++)
- purple_cipher_append(cipher, buff, 1000);
+ purple_hash_append(hash, buff, 1000);
}
- ret = purple_cipher_digest_to_str(cipher, digest, sizeof(digest));
+ ret = purple_hash_digest_to_str(hash, digest, sizeof(digest));
if(!ret) {
purple_debug_info("cipher-test", "failed\n");
@@ -164,11 +164,11 @@ cipher_test_sha1(void) {
sha1_tests[i].answer);
}
- purple_cipher_reset(cipher);
+ purple_hash_reset(hash);
i++;
}
- g_object_unref(cipher);
+ g_object_unref(hash);
purple_debug_info("cipher-test", "sha1 tests completed\n\n");
}
@@ -234,14 +234,6 @@ cipher_test_digest(void)
* PBKDF2 stuff
**************************************************************************/
-#ifdef HAVE_NSS
-# include <nss.h>
-# include <secmod.h>
-# include <pk11func.h>
-# include <prerror.h>
-# include <secerr.h>
-#endif
-
typedef struct {
const gchar *hash;
const guint iter_count;
@@ -261,108 +253,11 @@ pbkdf2_test pbkdf2_tests[] = {
{ NULL, 0, NULL, NULL, 0, NULL}
};
-#ifdef HAVE_NSS
-
-static gchar*
-cipher_pbkdf2_nss_sha1(const gchar *passphrase, const gchar *salt,
- guint iter_count, guint out_len)
-{
- PK11SlotInfo *slot;
- SECAlgorithmID *algorithm = NULL;
- PK11SymKey *symkey = NULL;
- const SECItem *symkey_data = NULL;
- SECItem salt_item, passphrase_item;
- guchar *passphrase_buff, *salt_buff;
- gchar *ret;
-
- g_return_val_if_fail(passphrase != NULL, NULL);
- g_return_val_if_fail(iter_count > 0, NULL);
- g_return_val_if_fail(out_len > 0, NULL);
-
- NSS_NoDB_Init(NULL);
More information about the Commits
mailing list