/soc/2013/ankitkv/gobjectification: 729bdf55b919: Merged soc.201...

Ankit Vani a at nevitus.org
Sun Oct 20 07:07:08 EDT 2013


Changeset: 729bdf55b91986c91d6fa9e73bfcbc9b8e7eff84
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-10-20 16:21 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/729bdf55b919

Description:

Merged soc.2013.gobjectification branch

diffstat:

 doc/reference/libpurple/libpurple-docs.xml   |    9 +-
 libpurple/Makefile.am                        |    2 -
 libpurple/Makefile.mingw                     |    3 +-
 libpurple/cipher.c                           |  217 ++++++++++++++++++++++++
 libpurple/cipher.h                           |  139 ++++++++++++++-
 libpurple/ciphers/aescipher.c                |    4 +-
 libpurple/ciphers/des3cipher.c               |    1 +
 libpurple/ciphers/descipher.c                |    1 +
 libpurple/ciphers/hmaccipher.c               |    1 +
 libpurple/ciphers/hmaccipher.h               |    1 -
 libpurple/ciphers/md4hash.c                  |    1 +
 libpurple/ciphers/md4hash.h                  |    2 +-
 libpurple/ciphers/md5hash.c                  |    1 +
 libpurple/ciphers/md5hash.h                  |    2 +-
 libpurple/ciphers/pbkdf2cipher.c             |    2 +-
 libpurple/ciphers/pbkdf2cipher.h             |    1 -
 libpurple/ciphers/rc4cipher.c                |    1 +
 libpurple/ciphers/sha1hash.c                 |    1 +
 libpurple/ciphers/sha1hash.h                 |    2 +-
 libpurple/ciphers/sha256hash.c               |    1 +
 libpurple/ciphers/sha256hash.h               |    2 +-
 libpurple/hash.c                             |  241 ---------------------------
 libpurple/hash.h                             |  168 ------------------
 libpurple/plugins/debug_example.c            |    2 +
 libpurple/plugins/helloworld.c               |    2 +
 libpurple/plugins/perl/Makefile.am           |    1 -
 libpurple/plugins/perl/common/Cipher.xs      |  105 +++++++++++
 libpurple/plugins/perl/common/Hash.xs        |  106 -----------
 libpurple/plugins/perl/common/MANIFEST       |    1 -
 libpurple/plugins/perl/common/Makefile.mingw |    1 -
 libpurple/plugins/perl/common/module.h       |    5 +-
 libpurple/protocols/jabber/auth_scram.h      |    2 +-
 libpurple/protocols/jabber/caps.h            |    2 +-
 libpurple/purple.h.in                        |    5 +-
 34 files changed, 486 insertions(+), 549 deletions(-)

diffs (truncated from 1441 to 300 lines):

diff --git a/doc/reference/libpurple/libpurple-docs.xml b/doc/reference/libpurple/libpurple-docs.xml
--- a/doc/reference/libpurple/libpurple-docs.xml
+++ b/doc/reference/libpurple/libpurple-docs.xml
@@ -38,6 +38,10 @@
       <xi:include href="xml/hmaccipher.xml" />
       <xi:include href="xml/pbkdf2cipher.xml" />
       <xi:include href="xml/rc4cipher.xml" />
+      <xi:include href="xml/md4hash.xml" />
+      <xi:include href="xml/md5hash.xml" />
+      <xi:include href="xml/sha1hash.xml" />
+      <xi:include href="xml/sha256hash.xml" />
       <xi:include href="xml/circularbuffer.xml" />
       <xi:include href="xml/cmds.xml" />
       <xi:include href="xml/connection.xml" />
@@ -52,11 +56,6 @@
       <xi:include href="xml/enums.xml" />
       <xi:include href="xml/eventloop.xml" />
       <xi:include href="xml/glibcompat.xml" />
-      <xi:include href="xml/hash.xml" />
-      <xi:include href="xml/md4hash.xml" />
-      <xi:include href="xml/md5hash.xml" />
-      <xi:include href="xml/sha1hash.xml" />
-      <xi:include href="xml/sha256hash.xml" />
       <xi:include href="xml/http.xml" />
       <xi:include href="xml/idle.xml" />
       <xi:include href="xml/imgstore.xml" />
diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -75,7 +75,6 @@ purple_coresources = \
 	debug.c \
 	desktopitem.c \
 	eventloop.c \
-	hash.c \
 	http.c \
 	idle.c \
 	imgstore.c \
@@ -152,7 +151,6 @@ purple_coreheaders = \
 	debug.h \
 	desktopitem.h \
 	eventloop.h \
-	hash.h \
 	http.h \
 	idle.h \
 	imgstore.h \
diff --git a/libpurple/Makefile.mingw b/libpurple/Makefile.mingw
--- a/libpurple/Makefile.mingw
+++ b/libpurple/Makefile.mingw
@@ -70,7 +70,6 @@ C_SRC =	\
 			buddylist.c \
 			buddyicon.c \
 			certificate.c \
-			cipher.c \
 			ciphers/aescipher.c \
 			ciphers/descipher.c \
 			ciphers/des3cipher.c \
@@ -81,6 +80,7 @@ C_SRC =	\
 			ciphers/rc4cipher.c \
 			ciphers/sha1hash.c \
 			ciphers/sha256hash.c \
+			cipher.c \
 			circularbuffer.c \
 			cmds.c \
 			connection.c \
@@ -92,7 +92,6 @@ C_SRC =	\
 			dnsquery.c \
 			dnssrv.c \
 			eventloop.c \
-			hash.c \
 			http.c \
 			idle.c \
 			imgstore.c \
diff --git a/libpurple/cipher.c b/libpurple/cipher.c
--- a/libpurple/cipher.c
+++ b/libpurple/cipher.c
@@ -335,3 +335,220 @@ purple_cipher_get_block_size(PurpleCiphe
 
 	return -1;
 }
+
+/******************************************************************************
+ * PurpleHash API
+ *****************************************************************************/
+GType
+purple_hash_get_type(void) {
+	static GType type = 0;
+
+	if(type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleHashClass),
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			sizeof(PurpleHash),
+			0,
+			NULL,
+			NULL
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT,
+									  "PurpleHash",
+									  &info, G_TYPE_FLAG_ABSTRACT);
+	}
+
+	return type;
+}
+
+/**
+ * purple_hash_reset:
+ * @hash: The hash to reset
+ *
+ * Resets a hash to it's default value
+ *
+ * @note If you have set an IV you will have to set it after resetting
+ */
+void
+purple_hash_reset(PurpleHash *hash) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->reset)
+		klass->reset(hash);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"reset method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+}
+
+/**
+ * Resets a hash state to it's default value, but doesn't touch stateless
+ * configuration.
+ *
+ * That means, IV and digest context will be wiped out, but keys, ops or salt
+ * will remain untouched.
+ */
+void
+purple_hash_reset_state(PurpleHash *hash) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->reset_state)
+		klass->reset_state(hash);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"reset_state method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+}
+
+/**
+ * purple_hash_append:
+ * @hash: The hash to append data to
+ * @data: The data to append
+ * @len: The length of the data
+ *
+ * Appends data to the hash
+ */
+void
+purple_hash_append(PurpleHash *hash, const guchar *data,
+								size_t len)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->append)
+		klass->append(hash, data, len);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"append method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+}
+
+/**
+ * purple_hash_digest:
+ * @hash: The hash to digest
+ * @in_len: The length of the buffer
+ * @digest: The return buffer for the digest
+ * @out_len: The length of the returned value
+ *
+ * Digests a hash
+ *
+ * Return Value: TRUE if the digest was successful, FALSE otherwise.
+ */
+gboolean
+purple_hash_digest(PurpleHash *hash, guchar digest[], size_t len)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->digest)
+		return klass->digest(hash, digest, len);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"digest method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+
+	return FALSE;
+}
+
+/**
+ * purple_hash_digest_to_str:
+ * @hash: The hash to get a digest from
+ * @in_len: The length of the buffer
+ * @digest_s: The return buffer for the string digest
+ * @out_len: The length of the returned value
+ *
+ * Converts a guchar digest into a hex string
+ *
+ * Return Value: TRUE if the digest was successful, FALSE otherwise.
+ */
+gboolean
+purple_hash_digest_to_str(PurpleHash *hash, gchar digest_s[], size_t len)
+{
+	/* 8k is a bit excessive, will tweak later. */
+	guchar digest[BUF_LEN * 4];
+	size_t digest_size, n;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE);
+	g_return_val_if_fail(digest_s, FALSE);
+
+	digest_size = purple_hash_get_digest_size(hash);
+
+	g_return_val_if_fail(digest_size <= BUF_LEN * 4, FALSE);
+
+	if(!purple_hash_digest(hash, digest, sizeof(digest)))
+		return FALSE;
+
+	/* Every digest byte occupies 2 chars + the NUL at the end. */
+	g_return_val_if_fail(digest_size * 2 + 1 <= len, FALSE);
+
+	for(n = 0; n < digest_size; n++)
+		sprintf(digest_s + (n * 2), "%02x", digest[n]);
+
+	digest_s[n * 2] = '\0';
+
+	return TRUE;
+}
+
+size_t
+purple_hash_get_digest_size(PurpleHash *hash)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->get_digest_size)
+		return klass->get_digest_size(hash);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"get_digest_size method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+
+	return FALSE;
+}
+
+/**
+ * purple_hash_get_block_size:
+ * @hash: The hash whose block size to get
+ *
+ * Gets the block size of a hash
+ *
+ * Return Value: The block size of the hash
+ */
+size_t
+purple_hash_get_block_size(PurpleHash *hash)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), -1);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->get_block_size)
+		return klass->get_block_size(hash);
+	else
+		purple_debug_warning("hash", "the %s hash does not implement the "
+						"get_block_size method\n",
+						g_type_name(G_TYPE_FROM_INSTANCE(hash)));
+
+	return -1;
+}
diff --git a/libpurple/cipher.h b/libpurple/cipher.h
--- a/libpurple/cipher.h
+++ b/libpurple/cipher.h
@@ -1,7 +1,6 @@



More information about the Commits mailing list