rizin/test/unit/test_crypto.c
Riccardo Schirone c4767cf1ac
Fix plugin removal and clean code (#3277)
* cmd: Fix summary of few "L" sub-commands
* util: start decluttering plugins handling

- Add Doxygen docs
- Remove unused API functions and make others internal only
- Use RzLibType enum for plugin type instead of int

* util: move dlopen/dlsym/dlclose to rz_sys
* util: make rz_lib_open/close return bool
* util: simplify rz_lib_add_handler and rz_lib_open*
* libs: implement rz_*_plugin_del to remove a plugin
* core: remove commands from RzCmd when removing plugins
* librz: call plugins 'fini' method when removing a plugin
* core/cmd: do not fail if the hashmap removal fails

When removing a group command, the inner command might have the same
name, thus it would result in trying to remove the same name twice.
Ignore it, as it is fine.

* librz: make RzCrypto plugins handling like the others
* librz/crypto: add rz_crypto_reset and use it
* librz: allocate the plugin structures before adding them
2023-01-16 13:32:46 +01:00

37 lines
1.1 KiB
C

// SPDX-FileCopyrightText: 2023 Riccardo Schirone <sirmy15@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_crypto.h>
#include "minunit.h"
bool test_use(void) {
RzCrypto *cry = rz_crypto_new();
rz_crypto_use(cry, "xor");
rz_crypto_set_key(cry, (ut8 *)"ABCD", 4, 0, RZ_CRYPTO_DIR_ENCRYPT);
rz_crypto_final(cry, (ut8 *)"ABCD", 4);
mu_assert_memeq(rz_crypto_get_output(cry, NULL), (ut8 *)"\x00\x00\x00\x00", 4, "xor same msg is 0");
rz_crypto_free(cry);
mu_end;
}
bool test_multi_use(void) {
RzCrypto *cry = rz_crypto_new();
rz_crypto_use(cry, "xor");
rz_crypto_set_key(cry, (ut8 *)"ABCD", 4, 0, RZ_CRYPTO_DIR_ENCRYPT);
rz_crypto_final(cry, (ut8 *)"ABCD", 4);
rz_crypto_reset(cry);
rz_crypto_use(cry, "xor");
rz_crypto_set_key(cry, (ut8 *)"ABCD", 4, 0, RZ_CRYPTO_DIR_DECRYPT);
rz_crypto_update(cry, (ut8 *)"\x00\x00\x00\x00", 4);
mu_assert_memeq(rz_crypto_get_output(cry, NULL), (ut8 *)"ABCD", 4, "xor with 0 is msg");
rz_crypto_free(cry);
mu_end;
}
bool all_tests() {
mu_run_test(test_use);
mu_run_test(test_multi_use);
return tests_passed != tests_run;
}
mu_main(all_tests)