33
44#include "Python.h"
55
6+ /*
7+ * Allow to use the 'data' or 'string' keyword in hashlib.new()
8+ * and other hash functions named constructors.
9+ *
10+ * - If 'data' and 'string' are both non-NULL, set an exception and return -1.
11+ * - If 'data' and 'string' are both NULL, set '*res' to NULL and return 0.
12+ * - Otherwise, set '*res' to 'data' or 'string' and return 1. A deprecation
13+ * warning is set when 'string' is specified.
14+ */
15+ extern int
16+ _Py_hashlib_data_argument (PyObject * * res , PyObject * data , PyObject * string );
17+
618/*
719 * Obtain a buffer view from a buffer-like object 'obj'.
820 *
921 * On success, store the result in 'view' and return 0.
1022 * On error, set an exception and return -1.
1123 */
12- static inline int
13- _Py_hashlib_get_buffer_view (PyObject * obj , Py_buffer * view )
14- {
15- if (PyUnicode_Check (obj )) {
16- PyErr_SetString (PyExc_TypeError ,
17- "Strings must be encoded before hashing" );
18- return -1 ;
19- }
20- if (!PyObject_CheckBuffer (obj )) {
21- PyErr_SetString (PyExc_TypeError ,
22- "object supporting the buffer API required" );
23- return -1 ;
24- }
25- if (PyObject_GetBuffer (obj , view , PyBUF_SIMPLE ) == -1 ) {
26- return -1 ;
27- }
28- if (view -> ndim > 1 ) {
29- PyErr_SetString (PyExc_BufferError ,
30- "Buffer must be single dimension" );
31- PyBuffer_Release (view );
32- return -1 ;
33- }
34- return 0 ;
35- }
24+ extern int
25+ _Py_hashlib_get_buffer_view (PyObject * obj , Py_buffer * view );
3626
3727/*
3828 * Call _Py_hashlib_get_buffer_view() and check if it succeeded.
@@ -51,18 +41,4 @@ _Py_hashlib_get_buffer_view(PyObject *obj, Py_buffer *view)
5141#define GET_BUFFER_VIEW_OR_ERROUT (OBJ , VIEW ) \
5242 GET_BUFFER_VIEW_OR_ERROR(OBJ, VIEW, return NULL)
5343
54- /*
55- * Allow to use the 'data' or 'string' keyword in hashlib.new()
56- * and other hash functions named constructors.
57- *
58- * - If 'data' and 'string' are both non-NULL, set an exception and return -1.
59- * - If 'data' and 'string' are both NULL, set '*res' to NULL and return 0.
60- * - Otherwise, set '*res' to 'data' or 'string' and return 1. A deprecation
61- * warning is set when 'string' is specified.
62- *
63- * The symbol is exported for '_hashlib' and HACL*-based extension modules.
64- */
65- PyAPI_FUNC (int )
66- _Py_hashlib_data_argument (PyObject * * res , PyObject * data , PyObject * string );
67-
6844#endif // !_HASHLIB_HASHLIB_BUFFER_H
0 commit comments