3
3
4
4
#include "Python.h"
5
5
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
+
6
18
/*
7
19
* Obtain a buffer view from a buffer-like object 'obj'.
8
20
*
9
21
* On success, store the result in 'view' and return 0.
10
22
* On error, set an exception and return -1.
11
23
*/
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 );
36
26
37
27
/*
38
28
* 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)
51
41
#define GET_BUFFER_VIEW_OR_ERROUT (OBJ , VIEW ) \
52
42
GET_BUFFER_VIEW_OR_ERROR(OBJ, VIEW, return NULL)
53
43
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
-
68
44
#endif // !_HASHLIB_HASHLIB_BUFFER_H
0 commit comments