Mercurial > pidgin
diff libpurple/util.c @ 17765:ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
| author | William Ehlhardt <williamehlhardt@gmail.com> |
|---|---|
| date | Fri, 25 May 2007 20:52:31 +0000 |
| parents | d8102e923bd1 |
| children | c588a4a9d287 6b7b13adb9b1 |
line wrap: on
line diff
--- a/libpurple/util.c Fri May 25 19:05:47 2007 +0000 +++ b/libpurple/util.c Fri May 25 20:52:31 2007 +0000 @@ -155,6 +155,31 @@ return data; } +gchar * +purple_base16_encode_chunked(const guchar *data, gsize len) +{ + int i; + gchar *ascii = NULL; + + g_return_val_if_fail(data != NULL, NULL); + g_return_val_if_fail(len > 0, NULL); + + /* For each byte of input, we need 2 bytes for the hex representation + * and 1 for the colon. + * The final colon will be replaced by a terminating NULL + */ + ascii = g_malloc(len * 3 + 1); + + for (i = 0; i < len; i++) + g_snprintf(&ascii[i * 3], 4, "%02hhx:", data[i]); + + /* Replace the final colon with NULL */ + ascii[len * 3 - 1] = 0; + + return ascii; +} + + /************************************************************************** * Base64 Functions **************************************************************************/
