Skip to content
Snippets Groups Projects
Commit 5f01efc9 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[*] Redid the base64 wrapping algorithm. Now it also works with binary data...

[*] Redid the base64 wrapping algorithm. Now it also works with binary data (PyBytesObject *) obtained from python
parent e84d5227
No related branches found
No related tags found
1 merge request!26Support 3689
......@@ -9,27 +9,25 @@
if (l_dap_enc_data_type < 1 || l_dap_enc_data_type > 2){
return NULL;
}
char* data = PyBytes_AsString(in_data);
size_t size_t_str = strlen(data);
char res[DAP_ENC_BASE64_ENCODE_SIZE(size_t_str)];
dap_enc_base64_encode(data, size_t_str,res, l_dap_enc_data_type);
PyBytesObject *out_obj = (PyBytesObject *)PyBytes_FromFormat("%s", res);
return Py_BuildValue("S", out_obj);
void *in_void = PyBytes_AsString((PyObject*)in_data);
size_t pySize = (size_t)PyBytes_GET_SIZE(in_data);
char result[DAP_ENC_BASE64_ENCODE_SIZE(pySize)];
dap_enc_base64_encode(in_void, pySize, result, l_dap_enc_data_type);
return Py_BuildValue("s", result);
}
PyObject *dap_decode_base64_py(PyObject *self, PyObject *args){
PyObject *data;
const char *in_str;
short int l_dap_enc_data_type=1;
if (!PyArg_ParseTuple(args, "S|h", &data, &l_dap_enc_data_type)) {
if (!PyArg_ParseTuple(args, "s|h", &in_str, &l_dap_enc_data_type)) {
return NULL;
}
if (l_dap_enc_data_type < 1 || l_dap_enc_data_type > 2){
return NULL;
}
char *in_data = PyBytes_AsString(data);
char *res = NULL;
res = DAP_NEW_SIZE(void, DAP_ENC_BASE64_ENCODE_SIZE(strlen(in_data)));
dap_enc_base64_decode(in_data, strlen(in_data), res, l_dap_enc_data_type);
PyBytesObject *pyBytesObject = (PyBytesObject *)PyBytes_FromFormat("%s", res);
return Py_BuildValue("S", pyBytesObject);
}
\ No newline at end of file
void *res = DAP_NEW_SIZE(void*, DAP_ENC_BASE64_ENCODE_SIZE(strlen(in_str)));
//size_t decrypted_size = dap_enc_base58_decode(in_str, res);
size_t decrypted_size = dap_enc_base64_decode(in_str, strlen(in_str), res, l_dap_enc_data_type);
PyBytesObject *return_object = (PyBytesObject*)PyBytes_FromStringAndSize(res, (Py_ssize_t)decrypted_size);
return Py_BuildValue("O", return_object);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment