TimestampSigner
This class extends the base Signer to include a timestamp in the signed output, allowing for time-limited signatures. It provides functionality to sign values with the current time and verify them against a maximum age during the unsigning process. If a signature has exceeded the specified duration, the class raises an exception to indicate expiration.
Constructor
Signature
def TimestampSigner() - > null
Methods
timestamp()
@classmethod
def timestamp() - > string
Generates a base62-encoded string representing the current Unix timestamp.
Returns
| Type | Description |
|---|---|
string | A base62-encoded string of the current system time used for signing. |
sign()
@classmethod
def sign(
value: string
) - > string
Appends a timestamp to the value before signing it to allow for expiration tracking.
Parameters
| Name | Type | Description |
|---|---|---|
| value | string | The raw string data that needs to be signed and timestamped. |
Returns
| Type | Description |
|---|---|
string | The signed value containing the original data, the separator, the timestamp, and the signature. |
unsign()
@classmethod
def unsign(
value: string,
max_age: integer|timedelta = null
) - > string
Retrieve original value and check it wasn't signed more than max_age seconds ago.
Parameters
| Name | Type | Description |
|---|---|---|
| value | string | The signed string containing the timestamp and signature to be verified. |
| max_age | `integer | timedelta` = null |
Returns
| Type | Description |
|---|---|
string | The original unsigned value if the signature is valid and has not expired. |