Compute the hex-encoded HMAC over a session-file body. Flask's SECRET_KEY may be str or bytes; both are accepted.
(secret, body)
| 63 | |
| 64 | |
| 65 | def _compute_file_hmac(secret, body): |
| 66 | """Compute the hex-encoded HMAC over a session-file body. |
| 67 | |
| 68 | Flask's SECRET_KEY may be str or bytes; both are accepted. |
| 69 | """ |
| 70 | key = secret.encode() if isinstance(secret, str) else secret |
| 71 | return hmac.new(key, body, _FILE_HMAC).hexdigest().encode() |
| 72 | |
| 73 | |
| 74 | # HKDF salt + info for the session-body Fernet key. Both fixed and version- |