| 38 #include "dbus-maybe.h" |
38 #include "dbus-maybe.h" |
| 39 #include "debug.h" |
39 #include "debug.h" |
| 40 #include "signals.h" |
40 #include "signals.h" |
| 41 #include "value.h" |
41 #include "value.h" |
| 42 |
42 |
| 43 #if GLIB_CHECK_VERSION(2,16,0) |
|
| 44 void |
|
| 45 purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type) |
|
| 46 { |
|
| 47 GChecksum *checksum; |
|
| 48 |
|
| 49 checksum = g_checksum_new(type); |
|
| 50 purple_cipher_context_set_data(context, checksum); |
|
| 51 } |
|
| 52 |
|
| 53 void |
|
| 54 purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type) |
|
| 55 { |
|
| 56 GChecksum *checksum; |
|
| 57 |
|
| 58 checksum = purple_cipher_context_get_data(context); |
|
| 59 g_return_if_fail(checksum != NULL); |
|
| 60 |
|
| 61 #if GLIB_CHECK_VERSION(2,18,0) |
|
| 62 g_checksum_reset(checksum); |
|
| 63 #else |
|
| 64 g_checksum_free(checksum); |
|
| 65 checksum = g_checksum_new(type); |
|
| 66 purple_cipher_context_set_data(context, checksum); |
|
| 67 #endif |
|
| 68 } |
|
| 69 |
|
| 70 void |
|
| 71 purple_g_checksum_uninit(PurpleCipherContext *context) |
|
| 72 { |
|
| 73 GChecksum *checksum; |
|
| 74 |
|
| 75 checksum = purple_cipher_context_get_data(context); |
|
| 76 g_return_if_fail(checksum != NULL); |
|
| 77 |
|
| 78 g_checksum_free(checksum); |
|
| 79 } |
|
| 80 |
|
| 81 void |
|
| 82 purple_g_checksum_append(PurpleCipherContext *context, const guchar *data, |
|
| 83 gsize len) |
|
| 84 { |
|
| 85 GChecksum *checksum; |
|
| 86 |
|
| 87 checksum = purple_cipher_context_get_data(context); |
|
| 88 g_return_if_fail(checksum != NULL); |
|
| 89 |
|
| 90 while (len >= G_MAXSSIZE) { |
|
| 91 g_checksum_update(checksum, data, G_MAXSSIZE); |
|
| 92 len -= G_MAXSSIZE; |
|
| 93 data += G_MAXSSIZE; |
|
| 94 } |
|
| 95 |
|
| 96 if (len) |
|
| 97 g_checksum_update(checksum, data, len); |
|
| 98 } |
|
| 99 |
|
| 100 gboolean |
|
| 101 purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type, |
|
| 102 gsize len, guchar *digest, gsize *out_len) |
|
| 103 { |
|
| 104 GChecksum *checksum; |
|
| 105 const gssize required_length = g_checksum_type_get_length(type); |
|
| 106 |
|
| 107 checksum = purple_cipher_context_get_data(context); |
|
| 108 |
|
| 109 g_return_val_if_fail(len >= required_length, FALSE); |
|
| 110 g_return_val_if_fail(checksum != NULL, FALSE); |
|
| 111 |
|
| 112 g_checksum_get_digest(checksum, digest, &len); |
|
| 113 |
|
| 114 purple_cipher_context_reset(context, NULL); |
|
| 115 |
|
| 116 if (out_len) |
|
| 117 *out_len = len; |
|
| 118 |
|
| 119 return TRUE; |
|
| 120 } |
|
| 121 #endif |
|
| 122 |
|
| 123 /******************************************************************************* |
43 /******************************************************************************* |
| 124 * Structs |
44 * Structs |
| 125 ******************************************************************************/ |
45 ******************************************************************************/ |
| 126 struct _PurpleCipher { |
46 struct _PurpleCipher { |
| 127 gchar *name; /**< Internal name - used for searching */ |
47 gchar *name; /**< Internal name - used for searching */ |