Jump to >

djblets.secrets.token_generators.vendor_checksum

Generator for tokens that contain an identifiable prefix and checksum.

New in version 3.0.

class VendorChecksumTokenGenerator[source]

Bases: djblets.secrets.token_generators.base.BaseTokenGenerator

Generator for tokens that contain an identifiable prefix and checksum.

Tokens of this format contain a prefix for identification (such as the vendor or type) and a checksum.

New in version 3.0.

token_generator_id: Optional[str] = 'vendor_checksum'[source]

The unique ID of the token generator, for registration purposes.

Type

str

CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'[source]

The character set to use for encoding the token.

Type

str

CHECKSUM_LENGTH = 6[source]

The length of the checksum portion of the token.

Type

int

HASH_RE = '^_[0-9A-Za-z]+$'[source]

A regex for validating the characters of a token.

Type

str

TOKEN_LENGTH = 255[source]

The total length of the token.

Type

int

create_token(token_info: Dict[str, Any] = {}, **kwargs) str[source]

Create a token that contains a prefix and checksum.

Parameters
  • token_info (dict) –

    A dictionary that must contain the following information about the token:

    Keys

    token_type (str) – The token prefix to set.

  • **kwargs (dict, unused) – Additional keyword arguments.

Returns

The token value.

Return type

str

Raises

KeyError – The token_info dictionary is missing a required key.

validate_token(token: str, token_info: Dict[str, Any] = {}, **kwargs) bool[source]

Return whether the token is a valid token from this generator.

Parameters
  • token (str) – The token to validate.

  • token_info (dict) –

    A dictionary that contains the following information about the token:

    Keys

    token_type (str) – The prefix that the token must have.

  • **kwargs (dict, unused) – Additional keyword arguments.

Returns

Whether the token is a valid token from this generator.

Return type

bool

__annotations__ = {'token_generator_id': 'Optional[str]'}