Encode and sign a pickle-able object. Return a (byte) string
(data, key, digestmod=None)
| 3456 | |
| 3457 | |
| 3458 | def cookie_encode(data, key, digestmod=None): |
| 3459 | """ Encode and sign a pickle-able object. Return a (byte) string """ |
| 3460 | depr(0, 13, "cookie_encode() will be removed soon.", |
| 3461 | "Do not use this API directly.") |
| 3462 | digestmod = digestmod or hashlib.sha256 |
| 3463 | msg = base64.b64encode(pickle.dumps(data, -1)) |
| 3464 | sig = base64.b64encode(hmac.new(tob(key), msg, digestmod=digestmod).digest()) |
| 3465 | return tob('!') + sig + tob('?') + msg |
| 3466 | |
| 3467 | |
| 3468 | def cookie_decode(data, key, digestmod=None): |