5 #include "ciphers/descipher.h"
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
;
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
);
23 g_assert_cmpmem(encrypt
, len
, answer
, len
);
26 answer
= g_new0(guchar
, len
+ 1);
27 ret
= purple_cipher_decrypt(cipher
, encrypt
, len
, answer
, len
);
29 g_assert_cmpmem(decrypt
, len
, answer
, len
);
35 g_object_unref(G_OBJECT(cipher
));
39 test_des_cipher_12345678(void) {
42 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
43 "\x06\x22\x05\xac\x6a\x0d\x55\xdd",
49 test_des_cipher_abcdefgh(void) {
52 "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
53 "\x62\xe0\xc6\x8c\x48\xe4\x75\xed",
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
);