From c030c8a29916178d67b45e560ddea483202070bd Mon Sep 17 00:00:00 2001 From: Alexey Stratulat <alexey.stratulat@demlabs.net> Date: Tue, 23 Jul 2019 18:01:50 +0700 Subject: [PATCH] [+] Made a test to check the implementation of base64 wrapping --- include/key_list.h | 12 ++++++++++-- include/libdap-crypto-python.h | 4 +++- include/wrapping_dap_enc_key.h | 10 +++++++++- test/test_b64.py | 24 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 test/test_b64.py diff --git a/include/key_list.h b/include/key_list.h index adb0783c..fffa8638 100644 --- a/include/key_list.h +++ b/include/key_list.h @@ -3,6 +3,10 @@ #include <stdint.h> #include <string.h> +#ifdef __cplusplus +extern "C" { +#endif + #undef LOG_TAG #define LOG_TAG "key-list" @@ -11,8 +15,12 @@ typedef struct key_list{ uint8_t lenght; }key_list_t; -key_list_t *key_list_init(); +key_list_t *key_list_init(void); void key_list_free(key_list_t* list); uint8_t key_list_add_element(key_list_t *list, dap_enc_key_t* key); bool key_list_del_element(key_list_t *list, uint8_t key); -dap_enc_key_t *key_list_get_key(key_list_t *list, uint8_t key); \ No newline at end of file +dap_enc_key_t *key_list_get_key(key_list_t *list, uint8_t key); + +#ifdef __cplusplus +} +#endif diff --git a/include/libdap-crypto-python.h b/include/libdap-crypto-python.h index 7a2bf372..15c19def 100644 --- a/include/libdap-crypto-python.h +++ b/include/libdap-crypto-python.h @@ -33,6 +33,8 @@ static PyMethodDef DapCryptoMethods[] = { {"logItInfo", dap_log_it_info, METH_VARARGS, ""}, {"newKey", dap_enc_key_new_py, METH_VARARGS, "The function creates a new key, and returns it with PyObject."}, {"delKey", dap_enc_key_delete_py, METH_VARARGS, ""}, + {"getEncSizeKey", dap_enc_key_get_enc_size_py, METH_VARARGS, ""}, + {"getDecSizeKey", dap_enc_key_get_dec_size_py, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; @@ -49,4 +51,4 @@ PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/include/wrapping_dap_enc_key.h b/include/wrapping_dap_enc_key.h index 824f99d7..b57bd12c 100644 --- a/include/wrapping_dap_enc_key.h +++ b/include/wrapping_dap_enc_key.h @@ -3,6 +3,10 @@ #include "dap_common.h" #include "key_list.h" +#ifdef __cplusplus +extern "C" { +#endif + #undef LOG_TAG #define LOG_TAG "wrapping-dap-enc-key" @@ -32,4 +36,8 @@ PyObject *dap_enc_gen_key_public_size_py(PyObject *self, PyObject *args);//dap_e PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key, void * a_output); ->int PyObject *dap_enc_key_signature_delete_py(PyObject *self, PyObject *args);//dap_enc_key_type_t a_key_type, uint8_t *a_sig_buf); ->void -PyObject *dap_enc_key_delete_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key); ->void \ No newline at end of file +PyObject *dap_enc_key_delete_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key); ->void + +#ifdef __cplusplus +} +#endif diff --git a/test/test_b64.py b/test/test_b64.py new file mode 100644 index 00000000..f03cf9bf --- /dev/null +++ b/test/test_b64.py @@ -0,0 +1,24 @@ +import libdap_crypto_python_module as crypto + +print ("Start test crypto b64") +s = "Test! I will crush Base64!" +print ("Input data: "+s) +crypt = crypto.encodeBase64(bytes(s, "utf-8"),1) +print ("Encrypted data: \t") +print(crypt) +decrypt = crypto.decodeBase64(crypt, 1) +print ("Decoded data: \t") +print(decrypt) +if bytes(s, "utf-8") == decrypt: + print ("TEST 1. Encode/Decode base64 done") +else: + print ("TEST 1. Encode/Decode base64 faild") + +print ("Test Base64 URLSAFE") +u = "http://kelvin.foundation/" +crypt_u = crypto.encodeBase64(bytes(u, "utf-8"), 2) +decrypt_u = crypto.decodeBase64(crypt_u) +if bytes(u, "utf-8") == decrypt_u: + print ("TEST 2. Encode/Decode base64 urlsafe done") +else: + print ("TEST 2. Encode/Decode base64 urlsafe faild") -- GitLab