libpurple/protocols/jabber/jutil.c

branch
soc.2013.gobjectification
changeset 34556
087db73b115d
parent 33909
773899cbd05a
child 34567
ea5103f66b0e
equal deleted inserted replaced
34555:9176f384669b 34556:087db73b115d
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 * 21 *
22 */ 22 */
23 #include "internal.h" 23 #include "internal.h"
24 #include "account.h" 24 #include "account.h"
25 #include "cipher.h"
26 #include "conversation.h" 25 #include "conversation.h"
27 #include "debug.h" 26 #include "debug.h"
28 #include "server.h" 27 #include "server.h"
29 #include "util.h" 28 #include "util.h"
30 #include "xmlnode.h" 29 #include "xmlnode.h"
31 30
32 #include "chat.h" 31 #include "chat.h"
33 #include "presence.h" 32 #include "presence.h"
34 #include "jutil.h" 33 #include "jutil.h"
34
35 #include "ciphers/md4.h"
36 #include "ciphers/md5.h"
37 #include "ciphers/sha1.h"
35 38
36 #ifdef USE_IDN 39 #ifdef USE_IDN
37 #include <idna.h> 40 #include <idna.h>
38 #include <stringprep.h> 41 #include <stringprep.h>
39 static char idn_buffer[1024]; 42 static char idn_buffer[1024];
734 737
735 char * 738 char *
736 jabber_calculate_data_hash(gconstpointer data, size_t len, 739 jabber_calculate_data_hash(gconstpointer data, size_t len,
737 const gchar *hash_algo) 740 const gchar *hash_algo)
738 { 741 {
739 PurpleCipherContext *context; 742 PurpleCipher *hash = NULL;
740 static gchar digest[129]; /* 512 bits hex + \0 */ 743 static gchar digest[129]; /* 512 bits hex + \0 */
741 744
742 context = purple_cipher_context_new_by_name(hash_algo, NULL); 745 /* FIXME: Check the source of this change and what we need here... */
743 if (context == NULL) 746 if (g_str_equal(hash_algo, "sha1"))
747 hash = purple_sha1_cipher_new();
748 else if (g_str_equal(hash_algo, "md4"))
749 hash = purple_md4_cipher_new();
750 else if (g_str_equal(hash_algo, "md5"))
751 hash = purple_md5_cipher_new();
752 if (hash == NULL)
744 { 753 {
745 purple_debug_error("jabber", "Could not find %s cipher\n", hash_algo); 754 purple_debug_error("jabber", "Could not find %s cipher\n", hash_algo);
746 g_return_val_if_reached(NULL); 755 g_return_val_if_reached(NULL);
747 } 756 }
748 757
749 /* Hash the data */ 758 /* Hash the data */
750 purple_cipher_context_append(context, data, len); 759 purple_cipher_append(hash, data, len);
751 if (!purple_cipher_context_digest_to_str(context, digest, sizeof(digest))) 760 if (!purple_cipher_digest_to_str(hash, digest, sizeof(digest)))
752 { 761 {
753 purple_debug_error("jabber", "Failed to get digest for %s cipher.\n", 762 purple_debug_error("jabber", "Failed to get digest for %s cipher.\n",
754 hash_algo); 763 hash_algo);
755 g_return_val_if_reached(NULL); 764 g_return_val_if_reached(NULL);
756 } 765 }
757 purple_cipher_context_destroy(context); 766 g_object_unref(G_OBJECT(hash));
758 767
759 return g_strdup(digest); 768 return g_strdup(digest);
760 } 769 }
761 770

mercurial