Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / libpurple / tests / test_des.c
blob608e47033a5c9cda11547d004082304af4bc74e4
1 #include <glib.h>
3 #include <purple.h>
5 #include "ciphers/descipher.h"
7 static void
8 test_des_cipher(const gchar *in, const gchar *key, const gchar *out, size_t len) {
9 PurpleCipher *cipher = NULL;
10 guchar *decrypt = NULL, *encrypt = NULL, *answer = NULL;
11 size_t ret = 0;
13 decrypt = g_memdup(in, len + 1);
14 encrypt = g_memdup(out, len + 1);
16 cipher = purple_des_cipher_new();
18 purple_cipher_set_key(cipher, (const guchar *)key, 8);
20 answer = g_new0(guchar, len + 1);
21 ret = purple_cipher_encrypt(cipher, decrypt, len, answer, len);
22 g_assert(ret == len);
23 g_assert_cmpmem(encrypt, len, answer, len);
24 g_free(answer);
26 answer = g_new0(guchar, len + 1);
27 ret = purple_cipher_decrypt(cipher, encrypt, len, answer, len);
28 g_assert(ret == len);
29 g_assert_cmpmem(decrypt, len, answer, len);
30 g_free(answer);
32 g_free(encrypt);
33 g_free(decrypt);
35 g_object_unref(G_OBJECT(cipher));
38 static void
39 test_des_cipher_12345678(void) {
40 test_des_cipher(
41 "12345678",
42 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
43 "\x06\x22\x05\xac\x6a\x0d\x55\xdd",
48 static void
49 test_des_cipher_abcdefgh(void) {
50 test_des_cipher(
51 "abcdefgh",
52 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
53 "\x62\xe0\xc6\x8c\x48\xe4\x75\xed",
58 gint
59 main(gint argc, gchar **argv) {
60 g_test_init(&argc, &argv, NULL);
62 g_test_add_func("/cipher/des/12345678",
63 test_des_cipher_12345678);
65 g_test_add_func("/cipher/des/abcdefgh",
66 test_des_cipher_abcdefgh);
68 return g_test_run();