Skip to content
Snippets Groups Projects
Commit 95d80e7c authored by dmitriy.gerasimov's avatar dmitriy.gerasimov
Browse files

Merge branch 'features-2780' into 'master'

Features 2780

See merge request libdap-crypto-python!3
parents e0fef50b 45ce7480
No related branches found
No related tags found
1 merge request!26Support 3689
......@@ -6,6 +6,7 @@ set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_C_STANDARD 11)
#set(SUBMODULES_NO_BUILD ON)
add_definitions("-fpic")
add_definitions("-DDAP_LOG_MT")
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if (NOT (TARGET dap_core))
......
#ifndef _WRAPPING_DAP_HASH_
#define _WRAPPING_DAP_HASH_
#include <Python.h>
#include "dap_hash.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyDapHashType{
PyObject_HEAD
dap_hash_type_t hash_type;
}PyDapHashTypeObject;
PyObject *DAP_HASH_TYPE_KECCAK_PY();
PyObject *DAP_HASH_TYPE_SLOW_0_PY();
static PyMethodDef DapHashTypeMethods[] = {
{"DAP_HASH_TYPE_KECCAK", (PyCFunction)DAP_HASH_TYPE_KECCAK_PY, METH_NOARGS | METH_STATIC, ""},
{"DAP_HASH_TYPE_SLOW_0", (PyCFunction)DAP_HASH_TYPE_SLOW_0_PY, METH_NOARGS | METH_STATIC, ""},
{NULL, NULL, 0, NULL}
};
static PyTypeObject DapChainHashTypeObject_DapChainHashTypeObjectType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.ChainHashType", /* tp_name */
sizeof(PyDapHashTypeObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Chain hash type object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapHashTypeMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
/*=================*/
/* Chain hash fast */
typedef struct PyDapChainHashFast{
PyObject_HEAD
dap_chain_hash_fast_t *hash_fast;
}PyDapChainHashFastObject;
PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args);
PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args);
PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args);
static PyMethodDef DapHashFastMethods[] = {
{"strToHashFast", (PyCFunction)dap_chain_str_to_hash_fast_py, METH_VARARGS | METH_STATIC, ""},
{"hashFast", (PyCFunction)dap_hash_fast_py, METH_VARARGS, ""},
{"compare", (PyCFunction)dap_hash_fast_compare_py, METH_VARARGS | METH_STATIC, ""},
{"isBlank", (PyCFunction)dap_hash_fast_is_blank_py, METH_VARARGS, ""},
{"toStr", (PyCFunction)dap_chain_hash_fast_to_str_py, METH_VARARGS, ""},
{"toStrNew", (PyCFunction)dap_chain_hash_fast_to_str_new_py, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
static PyTypeObject DapChainHashFastObject_DapChainHashFastObjectType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.ChainFast", /* tp_name */
sizeof(PyDapChainHashFastObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Chain hash fast object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapHashFastMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
#ifdef __cplusplus
}
#endif
#endif // _WRAPPING_DAP_HASH_
Subproject commit f91fb3b3b6a69ef53531c8fd729592cdff4ec442
Subproject commit ee6e8617e1f589b45f15e327ed18cddfa87915f8
Subproject commit bb48d2efb77ee770c6f36c296811688f2ad9c348
Subproject commit 16a16e71b9cfae4fd8df530ed8cd6146010ae7e0
#include "wrapping_dap_hash.h"
PyObject *DAP_HASH_TYPE_KECCAK_PY(){
PyObject *obj = _PyObject_New(&DapChainHashTypeObject_DapChainHashTypeObjectType);
((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_KECCAK;
return Py_BuildValue("O", obj);
}
PyObject *DAP_HASH_TYPE_SLOW_0_PY(){
PyObject *obj = _PyObject_New(&DapChainHashTypeObject_DapChainHashTypeObjectType);
((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_SLOW_0;
return Py_BuildValue("O", obj);
}
PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args){
const char *hash_str;
PyObject *obj_hash_fast;
if (!PyArg_ParseTuple(args, "s|O", &hash_str, &obj_hash_fast))
return NULL;
int res = dap_chain_str_to_hash_fast(hash_str, ((PyDapChainHashFastObject*)obj_hash_fast)->hash_fast);
return Py_BuildValue("nO", res, obj_hash_fast);
}
PyObject *dap_hash_fast_py(PyObject *self, PyObject *args){
PyObject *obj_bytes;
size_t data_in_size;
if (!PyArg_ParseTuple(args, "O|n", &obj_bytes, &data_in_size))
return NULL;
const void *bytes = (void*)PyBytes_AsString(obj_bytes);
bool res = dap_hash_fast(bytes, data_in_size, ((PyDapChainHashFastObject*)self)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args){
PyObject *hash1;
PyObject *hash2;
if (!PyArg_ParseTuple(args, "O|O", &hash1, &hash2))
return NULL;
bool res = dap_hash_fast_compare(((PyDapChainHashFastObject*)hash1)->hash_fast, ((PyDapChainHashFastObject*)hash2)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args){
bool res = dap_hash_fast_is_blank(((PyDapChainHashFastObject*)self)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args){
char *str;
size_t str_max;
if (!PyArg_ParseTuple(args, "s|n", &str, &str_max))
return NULL;
int res = dap_chain_hash_fast_to_str(((PyDapChainHashFastObject*)self)->hash_fast, str, str_max);
return Py_BuildValue("sn", &str, &str_max);
}
PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args){
char *res = dap_chain_hash_fast_to_str_new(((PyDapChainHashFastObject*)self)->hash_fast);
return Py_BuildValue("s", res);
}
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