| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4b8a7f5 commit f1d36d8
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,7 +101,7 @@ More condensed: | |||
| 101 | 101 | ||
| 102 | 102 | .. function:: new(name[, data]) | |
| 103 | 103 | ||
| 104 | - Is a generic constructor that takes the string name of the desired | ||
| 104 | + Is a generic constructor that takes the string *name* of the desired | ||
| 105 | 105 | algorithm as its first parameter. It also exists to allow access to the | |
| 106 | 106 | above listed hashes as well as any other algorithms that your OpenSSL | |
| 107 | 107 | library may offer. The named constructors are much faster than :func:`new` | |
@@ -162,10 +162,10 @@ A hash object has the following attributes: | |||
| 162 | 162 | A hash object has the following methods: | |
| 163 | 163 | ||
| 164 | 164 | ||
| 165 | - .. method:: hash.update(arg) | ||
| 165 | + .. method:: hash.update(data) | ||
| 166 | 166 | ||
| 167 | - Update the hash object with the object *arg*, which must be interpretable as | ||
| 168 | - a buffer of bytes. Repeated calls are equivalent to a single call with the | ||
| 167 | + Update the hash object with the :term:`bytes-like object`. | ||
| 168 | + Repeated calls are equivalent to a single call with the | ||
| 169 | 169 | concatenation of all the arguments: ``m.update(a); m.update(b)`` is | |
| 170 | 170 | equivalent to ``m.update(a+b)``. | |
| 171 | 171 | ||
@@ -206,7 +206,7 @@ by the SHAKE algorithm. | |||
| 206 | 206 | .. method:: shake.digest(length) | |
| 207 | 207 | ||
| 208 | 208 | Return the digest of the data passed to the :meth:`update` method so far. | |
| 209 | - This is a bytes object of size ``length`` which may contain bytes in | ||
| 209 | + This is a bytes object of size *length* which may contain bytes in | ||
| 210 | 210 | the whole range from 0 to 255. | |
| 211 | 211 | ||
| 212 | 212 | ||
@@ -262,9 +262,10 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_. | |||
| 262 | 262 | The function provides scrypt password-based key derivation function as | |
| 263 | 263 | defined in :rfc:`7914`. | |
| 264 | 264 | ||
| 265 | - *password* and *salt* must be bytes-like objects. Applications and | ||
| 266 | - libraries should limit *password* to a sensible length (e.g. 1024). *salt* | ||
| 267 | - should be about 16 or more bytes from a proper source, e.g. :func:`os.urandom`. | ||
| 265 | + *password* and *salt* must be :term:`bytes-like objects | ||
| 266 | + <bytes-like object>`. Applications and libraries should limit *password* | ||
| 267 | + to a sensible length (e.g. 1024). *salt* should be about 16 or more | ||
| 268 | + bytes from a proper source, e.g. :func:`os.urandom`. | ||
| 268 | 269 | ||
| 269 | 270 | *n* is the CPU/Memory cost factor, *r* the block size, *p* parallelization | |
| 270 | 271 | factor and *maxmem* limits memory (OpenSSL 1.1.0 defaults to 32 MiB). | |
@@ -305,20 +306,20 @@ Creating hash objects | |||
| 305 | 306 | New hash objects are created by calling constructor functions: | |
| 306 | 307 | ||
| 307 | 308 | ||
| 308 | - .. function:: blake2b(data=b'', digest_size=64, key=b'', salt=b'', \ | ||
| 309 | + .. function:: blake2b(data=b'', *, digest_size=64, key=b'', salt=b'', \ | ||
| 309 | 310 | person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \ | |
| 310 | 311 | node_depth=0, inner_size=0, last_node=False) | |
| 311 | 312 | ||
| 312 | - .. function:: blake2s(data=b'', digest_size=32, key=b'', salt=b'', \ | ||
| 313 | + .. function:: blake2s(data=b'', *, digest_size=32, key=b'', salt=b'', \ | ||
| 313 | 314 | person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \ | |
| 314 | 315 | node_depth=0, inner_size=0, last_node=False) | |
| 315 | 316 | ||
| 316 | 317 | ||
| 317 | 318 | These functions return the corresponding hash objects for calculating | |
| 318 | 319 | BLAKE2b or BLAKE2s. They optionally take these general parameters: | |
| 319 | 320 | ||
| 320 | - * *data*: initial chunk of data to hash, which must be interpretable as buffer | ||
| 321 | - of bytes. | ||
| 321 | + * *data*: initial chunk of data to hash, which must be | ||
| 322 | + :term:`bytes-like object`. It can be passed only as positional argument. | ||
| 322 | 323 | ||
| 323 | 324 | * *digest_size*: size of output digest in bytes. | |
| 324 | 325 | ||
@@ -427,7 +428,7 @@ object, and, finally, get the digest out of the object by calling | |||
| 427 | 428 | ||
| 428 | 429 | ||
| 429 | 430 | As a shortcut, you can pass the first chunk of data to update directly to the | |
| 430 | - constructor as the first argument (or as *data* keyword argument): | ||
| 431 | + constructor as the positional argument: | ||
| 431 | 432 | ||
| 432 | 433 | >>> from hashlib import blake2b | |
| 433 | 434 | >>> blake2b(b'Hello world').hexdigest() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,18 +25,18 @@ | |||
| 25 | 25 | sha384 and sha512 will be slow on 32 bit platforms. | |
| 26 | 26 | ||
| 27 | 27 | Hash objects have these methods: | |
| 28 | - - update(arg): Update the hash object with the bytes in arg. Repeated calls | ||
| 29 | - are equivalent to a single call with the concatenation of all | ||
| 30 | - the arguments. | ||
| 31 | - - digest(): Return the digest of the bytes passed to the update() method | ||
| 32 | - so far. | ||
| 33 | - - hexdigest(): Like digest() except the digest is returned as a unicode | ||
| 34 | - object of double length, containing only hexadecimal digits. | ||
| 35 | - - copy(): Return a copy (clone) of the hash object. This can be used to | ||
| 36 | - efficiently compute the digests of strings that share a common | ||
| 37 | - initial substring. | ||
| 38 | - | ||
| 39 | - For example, to obtain the digest of the string 'Nobody inspects the | ||
| 28 | + - update(data): Update the hash object with the bytes in data. Repeated calls | ||
| 29 | + are equivalent to a single call with the concatenation of all | ||
| 30 | + the arguments. | ||
| 31 | + - digest(): Return the digest of the bytes passed to the update() method | ||
| 32 | + so far as a bytes object. | ||
| 33 | + - hexdigest(): Like digest() except the digest is returned as a string | ||
| 34 | + of double length, containing only hexadecimal digits. | ||
| 35 | + - copy(): Return a copy (clone) of the hash object. This can be used to | ||
| 36 | + efficiently compute the digests of datas that share a common | ||
| 37 | + initial substring. | ||
| 38 | + | ||
| 39 | + For example, to obtain the digest of the byte string 'Nobody inspects the | ||
| 40 | 40 | spammish repetition': | |
| 41 | 41 | ||
| 42 | 42 | >>> import hashlib | |
@@ -130,14 +130,15 @@ def __get_openssl_constructor(name): | |||
| 130 | 130 | ||
| 131 | 131 | def __py_new(name, data=b'', **kwargs): | |
| 132 | 132 | """new(name, data=b'', **kwargs) - Return a new hashing object using the | |
| 133 | - named algorithm; optionally initialized with data (which must be bytes). | ||
| 133 | + named algorithm; optionally initialized with data (which must be | ||
| 134 | + a bytes-like object). | ||
| 134 | 135 | """ | |
| 135 | 136 | return __get_builtin_constructor(name)(data, **kwargs) | |
| 136 | 137 | ||
| 137 | 138 | ||
| 138 | 139 | def __hash_new(name, data=b'', **kwargs): | |
| 139 | 140 | """new(name, data=b'') - Return a new hashing object using the named algorithm; | |
| 140 | - optionally initialized with data (which must be bytes). | ||
| 141 | + optionally initialized with data (which must be a bytes-like object). | ||
| 141 | 142 | """ | |
| 142 | 143 | if name in {'blake2b', 'blake2s'}: | |
| 143 | 144 | # Prefer our blake2 implementation. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -568,8 +568,12 @@ def check_blake2(self, constructor, salt_size, person_size, key_size, | |||
| 568 | 568 | self.assertRaises(ValueError, constructor, node_offset=-1) | |
| 569 | 569 | self.assertRaises(OverflowError, constructor, node_offset=max_offset+1) | |
| 570 | 570 | ||
| 571 | + self.assertRaises(TypeError, constructor, data=b'') | ||
| 572 | + self.assertRaises(TypeError, constructor, string=b'') | ||
| 573 | + self.assertRaises(TypeError, constructor, '') | ||
| 574 | + | ||
| 571 | 575 | constructor( | |
| 572 | - string=b'', | ||
| 576 | + b'', | ||
| 573 | 577 | key=b'', | |
| 574 | 578 | salt=b'', | |
| 575 | 579 | person=b'', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Fixed issues with arguments parsing in :mod:`hashlib`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,10 +47,10 @@ typedef struct { | |||
| 47 | 47 | #include "clinic/blake2b_impl.c.h" | |
| 48 | 48 | ||
| 49 | 49 | /*[clinic input] | |
| 50 | - module _blake2b | ||
| 51 | - class _blake2b.blake2b "BLAKE2bObject *" "&PyBlake2_BLAKE2bType" | ||
| 50 | + module _blake2 | ||
| 51 | + class _blake2.blake2b "BLAKE2bObject *" "&PyBlake2_BLAKE2bType" | ||
| 52 | 52 | [clinic start generated code]*/ | |
| 53 | - /*[clinic end generated code: output=da39a3ee5e6b4b0d input=6893358c6622aecf]*/ | ||
| 53 | + /*[clinic end generated code: output=da39a3ee5e6b4b0d input=d47b0527b39c673f]*/ | ||
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | 56 | static BLAKE2bObject * | |
@@ -66,13 +66,14 @@ new_BLAKE2bObject(PyTypeObject *type) | |||
| 66 | 66 | ||
| 67 | 67 | /*[clinic input] | |
| 68 | 68 | @classmethod | |
| 69 | - _blake2b.blake2b.__new__ as py_blake2b_new | ||
| 70 | - string as data: object = NULL | ||
| 69 | + _blake2.blake2b.__new__ as py_blake2b_new | ||
| 70 | + data: object(c_default="NULL") = b'' | ||
| 71 | + / | ||
| 71 | 72 | * | |
| 72 | - digest_size: int(c_default="BLAKE2B_OUTBYTES") = _blake2b.blake2b.MAX_DIGEST_SIZE | ||
| 73 | - key: Py_buffer = None | ||
| 74 | - salt: Py_buffer = None | ||
| 75 | - person: Py_buffer = None | ||
| 73 | + digest_size: int(c_default="BLAKE2B_OUTBYTES") = _blake2.blake2b.MAX_DIGEST_SIZE | ||
| 74 | + key: Py_buffer(c_default="NULL", py_default="b''") = None | ||
| 75 | + salt: Py_buffer(c_default="NULL", py_default="b''") = None | ||
| 76 | + person: Py_buffer(c_default="NULL", py_default="b''") = None | ||
| 76 | 77 | fanout: int = 1 | |
| 77 | 78 | depth: int = 1 | |
| 78 | 79 | leaf_size: unsigned_long = 0 | |
@@ -90,7 +91,7 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, | |||
| 90 | 91 | int fanout, int depth, unsigned long leaf_size, | |
| 91 | 92 | unsigned long long node_offset, int node_depth, | |
| 92 | 93 | int inner_size, int last_node) | |
| 93 | - /*[clinic end generated code: output=65e732c66c2297a0 input=75ab5196b695adee]*/ | ||
| 94 | + /*[clinic end generated code: output=65e732c66c2297a0 input=82be35a4e6a9daa2]*/ | ||
| 94 | 95 | { | |
| 95 | 96 | BLAKE2bObject *self = NULL; | |
| 96 | 97 | Py_buffer buf; | |
@@ -237,14 +238,14 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, | |||
| 237 | 238 | } | |
| 238 | 239 | ||
| 239 | 240 | /*[clinic input] | |
| 240 | - _blake2b.blake2b.copy | ||
| 241 | + _blake2.blake2b.copy | ||
| 241 | 242 | ||
| 242 | 243 | Return a copy of the hash object. | |
| 243 | 244 | [clinic start generated code]*/ | |
| 244 | 245 | ||
| 245 | 246 | static PyObject * | |
| 246 | - _blake2b_blake2b_copy_impl(BLAKE2bObject *self) | ||
| 247 | - /*[clinic end generated code: output=c89cd33550ab1543 input=4c9c319f18f10747]*/ | ||
| 247 | + _blake2_blake2b_copy_impl(BLAKE2bObject *self) | ||
| 248 | + /*[clinic end generated code: output=ff6acee5f93656ae input=e383c2d199fd8a2e]*/ | ||
| 248 | 249 | { | |
| 249 | 250 | BLAKE2bObject *cpy; | |
| 250 | 251 | ||
@@ -259,21 +260,21 @@ _blake2b_blake2b_copy_impl(BLAKE2bObject *self) | |||
| 259 | 260 | } | |
| 260 | 261 | ||
| 261 | 262 | /*[clinic input] | |
| 262 | - _blake2b.blake2b.update | ||
| 263 | + _blake2.blake2b.update | ||
| 263 | 264 | ||
| 264 | - obj: object | ||
| 265 | + data: object | ||
| 265 | 266 | / | |
| 266 | 267 | ||
| 267 | - Update this hash object's state with the provided string. | ||
| 268 | + Update this hash object's state with the provided bytes-like object. | ||
| 268 | 269 | [clinic start generated code]*/ | |
| 269 | 270 | ||
| 270 | 271 | static PyObject * | |
| 271 | - _blake2b_blake2b_update(BLAKE2bObject *self, PyObject *obj) | ||
| 272 | - /*[clinic end generated code: output=a888f07c4cddbe94 input=3ecb8c13ee4260f2]*/ | ||
| 272 | + _blake2_blake2b_update(BLAKE2bObject *self, PyObject *data) | ||
| 273 | + /*[clinic end generated code: output=010dfcbe22654359 input=ffc4aa6a6a225d31]*/ | ||
| 273 | 274 | { | |
| 274 | 275 | Py_buffer buf; | |
| 275 | 276 | ||
| 276 | - GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); | ||
| 277 | + GET_BUFFER_VIEW_OR_ERROUT(data, &buf); | ||
| 277 | 278 | ||
| 278 | 279 | if (self->lock == NULL && buf.len >= HASHLIB_GIL_MINSIZE) | |
| 279 | 280 | self->lock = PyThread_allocate_lock(); | |
@@ -293,14 +294,14 @@ _blake2b_blake2b_update(BLAKE2bObject *self, PyObject *obj) | |||
| 293 | 294 | } | |
| 294 | 295 | ||
| 295 | 296 | /*[clinic input] | |
| 296 | - _blake2b.blake2b.digest | ||
| 297 | + _blake2.blake2b.digest | ||
| 297 | 298 | ||
| 298 | - Return the digest value as a string of binary data. | ||
| 299 | + Return the digest value as a bytes object. | ||
| 299 | 300 | [clinic start generated code]*/ | |
| 300 | 301 | ||
| 301 | 302 | static PyObject * | |
| 302 | - _blake2b_blake2b_digest_impl(BLAKE2bObject *self) | ||
| 303 | - /*[clinic end generated code: output=b13a79360d984740 input=ac2fa462ebb1b9c7]*/ | ||
| 303 | + _blake2_blake2b_digest_impl(BLAKE2bObject *self) | ||
| 304 | + /*[clinic end generated code: output=a5864660f4bfc61a input=7d21659e9c5fff02]*/ | ||
| 304 | 305 | { | |
| 305 | 306 | uint8_t digest[BLAKE2B_OUTBYTES]; | |
| 306 | 307 | blake2b_state state_cpy; | |
@@ -314,14 +315,14 @@ _blake2b_blake2b_digest_impl(BLAKE2bObject *self) | |||
| 314 | 315 | } | |
| 315 | 316 | ||
| 316 | 317 | /*[clinic input] | |
| 317 | - _blake2b.blake2b.hexdigest | ||
| 318 | + _blake2.blake2b.hexdigest | ||
| 318 | 319 | ||
| 319 | 320 | Return the digest value as a string of hexadecimal digits. | |
| 320 | 321 | [clinic start generated code]*/ | |
| 321 | 322 | ||
| 322 | 323 | static PyObject * | |
| 323 | - _blake2b_blake2b_hexdigest_impl(BLAKE2bObject *self) | ||
| 324 | - /*[clinic end generated code: output=6a503611715b24bd input=d58f0b2f37812e33]*/ | ||
| 324 | + _blake2_blake2b_hexdigest_impl(BLAKE2bObject *self) | ||
| 325 | + /*[clinic end generated code: output=b5598a87d8794a60 input=76930f6946351f56]*/ | ||
| 325 | 326 | { | |
| 326 | 327 | uint8_t digest[BLAKE2B_OUTBYTES]; | |
| 327 | 328 | blake2b_state state_cpy; | |
@@ -335,10 +336,10 @@ _blake2b_blake2b_hexdigest_impl(BLAKE2bObject *self) | |||
| 335 | 336 | ||
| 336 | 337 | ||
| 337 | 338 | static PyMethodDef py_blake2b_methods[] = { | |
| 338 | - _BLAKE2B_BLAKE2B_COPY_METHODDEF | ||
| 339 | - _BLAKE2B_BLAKE2B_DIGEST_METHODDEF | ||
| 340 | - _BLAKE2B_BLAKE2B_HEXDIGEST_METHODDEF | ||
| 341 | - _BLAKE2B_BLAKE2B_UPDATE_METHODDEF | ||
| 339 | + _BLAKE2_BLAKE2B_COPY_METHODDEF | ||
| 340 | + _BLAKE2_BLAKE2B_DIGEST_METHODDEF | ||
| 341 | + _BLAKE2_BLAKE2B_HEXDIGEST_METHODDEF | ||
| 342 | + _BLAKE2_BLAKE2B_UPDATE_METHODDEF | ||
| 342 | 343 | {NULL, NULL} | |
| 343 | 344 | }; | |
| 344 | 345 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments