Signs and timestamps a string so it cannot be forged. Normally used via set_secure_cookie, but provided as a separate method for non-cookie uses. To decode a value not stored as a cookie use the optional value argument to get_secure_cookie. .. versionchanged:: 3.2.
(
self, name: str, value: Union[str, bytes], version: Optional[int] = None
)
| 724 | ) |
| 725 | |
| 726 | def create_signed_value( |
| 727 | self, name: str, value: Union[str, bytes], version: Optional[int] = None |
| 728 | ) -> bytes: |
| 729 | """Signs and timestamps a string so it cannot be forged. |
| 730 | |
| 731 | Normally used via set_secure_cookie, but provided as a separate |
| 732 | method for non-cookie uses. To decode a value not stored |
| 733 | as a cookie use the optional value argument to get_secure_cookie. |
| 734 | |
| 735 | .. versionchanged:: 3.2.1 |
| 736 | |
| 737 | Added the ``version`` argument. Introduced cookie version 2 |
| 738 | and made it the default. |
| 739 | """ |
| 740 | self.require_setting("cookie_secret", "secure cookies") |
| 741 | secret = self.application.settings["cookie_secret"] |
| 742 | key_version = None |
| 743 | if isinstance(secret, dict): |
| 744 | if self.application.settings.get("key_version") is None: |
| 745 | raise Exception("key_version setting must be used for secret_key dicts") |
| 746 | key_version = self.application.settings["key_version"] |
| 747 | |
| 748 | return create_signed_value( |
| 749 | secret, name, value, version=version, key_version=key_version |
| 750 | ) |
| 751 | |
| 752 | def get_secure_cookie( |
| 753 | self, |
no test coverage detected