bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomiextern void var_expand_crypt_init(struct module *module);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomiextern void var_expand_crypt_deinit(void);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { '\0', "98b3b40a48ca40f998b3b40a48ca40f9", "iv" },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { '\0', "cc2981c8f38aea59cc2981c8f38aea59", "key" },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { '\0', "46b58741763fe22598014be26331a082", "encrypted_noiv" },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { '\0', "98b3b40a48ca40f998b3b40a48ca40f9$46b58741763fe22598014be26331a082$", "encrypted" },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi static struct {
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{encrypt;algo=aes-128-cbc,iv=98b3b40a48ca40f998b3b40a48ca40f9,key=cc2981c8f38aea59cc2981c8f38aea59:decrypted}", "98b3b40a48ca40f998b3b40a48ca40f9$46b58741763fe22598014be26331a082$", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{encrypt;noiv=yes,algo=aes-128-cbc,iv=98b3b40a48ca40f998b3b40a48ca40f9,key=cc2981c8f38aea59cc2981c8f38aea59:decrypted}", "46b58741763fe22598014be26331a082", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{encrypt;algo=aes-128-cbc,iv=%{iv},key=%{key}:decrypted}", "98b3b40a48ca40f998b3b40a48ca40f9$46b58741763fe22598014be26331a082$", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{decrypt;algo=aes-128-cbc,key=%{key}:encrypted}", "hello, world", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{decrypt;algo=aes-128-cbc,iv=%{iv},key=%{key}:encrypted_noiv}", "hello, world", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi { "%{decrypt;algo=aes-128-cbc,iv=98b3b40a48ca40f998b3b40a48ca40f9,key=cc2981c8f38aea59cc2981c8f38aea59:encrypted_noiv}", "hello, world", 1 },
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi unsigned int i;
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi for(i=0; i < N_ELEMENTS(test_cases); i++) T_BEGIN {
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi int ret = var_expand(dest, test_cases[i].input, table, &error);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi i_info("Expected: var_expand(%s): %s", test_cases[i].input, error);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi i_error("var_expand(%s): %s", test_cases[i].input, error);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi test_assert_idx(strcmp(str_c(dest), test_cases[i].output)==0, i);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi test_assert_idx(ret == test_cases[i].expect_ret, i);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi for(i=0;i<1000;i++) {
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi test_assert_idx(var_expand(input, "%{encrypt;algo=aes-128-cbc,key=%{key}:decrypted}", table, &error) == 1, i);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi test_assert_idx(var_expand(output, "%{decrypt;algo=aes-128-cbc,key=%{key}:encrypted2}", table, &error) == 1, i);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi test_assert_idx(strcmp(str_c(output), table[4].value)==0, i);
205f29a013ee4aa95e9be993ebf261a9d9bc251bAki Tuomi static void (*const test_functions[])(void) = {