Verify and decode an encoded string. Return an object or None.
(data, key)
| 2608 | |
| 2609 | |
| 2610 | def cookie_decode(data, key): |
| 2611 | ''' Verify and decode an encoded string. Return an object or None.''' |
| 2612 | data = tob(data) |
| 2613 | if cookie_is_encoded(data): |
| 2614 | sig, msg = data.split(tob('?'), 1) |
| 2615 | if _lscmp(sig[1:], base64.b64encode(hmac.new(tob(key), msg, digestmod=hashlib.md5).digest())): |
| 2616 | return pickle.loads(base64.b64decode(msg)) |
| 2617 | return None |
| 2618 | |
| 2619 | |
| 2620 | def cookie_is_encoded(data): |
no test coverage detected