# keystone.receipt.receipt_formatters module

class keystone.receipt.receipt_formatters.ReceiptFormatter

  Bases: `object`

  Packs and unpacks payloads into receipts for transport.

  create_receipt(user_id, methods, expires_at)

    Given a set of payload attributes, generate a Fernet receipt.

  classmethod creation_time(fernet_receipt)

    Return the creation time of a valid Fernet receipt.

  property crypto

    Return a cryptography instance.

    You can extend this class with a custom crypto @property to provide your own receipt encoding / decoding. For example, using a different cryptography library (e.g. `python-keyczar`) or to meet arbitrary security requirements.

    This @property just needs to return an object that implements `encrypt(plaintext)` and `decrypt(ciphertext)`.

  pack(payload)

    Pack a payload for transport as a receipt.

    Return type:

      str

  classmethod restore_padding(receipt)

    Restore padding based on receipt size.

    Parameters:

      receipt (str) – receipt to restore padding on

    Returns:

      receipt with correct padding

  unpack(receipt)

    Unpack a receipt, and validate the payload.

    Return type:

      bytes

  validate_receipt(receipt)

    Validate a Fernet receipt and returns the payload attributes.

class keystone.receipt.receipt_formatters.ReceiptPayload

  Bases: `object`

  classmethod assemble(user_id, methods, expires_at)

    Assemble the payload of a receipt.

    Parameters:

      - user_id – identifier of the user in the receipt request

      - methods – list of authentication methods used

      - expires_at – datetime of the receipt’s expiration

    Returns:

      the payload of a receipt

  classmethod attempt_convert_uuid_hex_to_bytes(value)

    Attempt to convert value to bytes or return value.

    Parameters:

      value – value to attempt to convert to bytes

    Returns:

      tuple containing boolean indicating whether user_id was stored as bytes and uuid value as bytes or the original value

  classmethod base64_encode(s)

    Encode a URL-safe string.

    Return type:

      str

  classmethod convert_uuid_bytes_to_hex(uuid_byte_string)

    Generate uuid.hex format based on byte string.

    Parameters:

      uuid_byte_string – uuid string to generate from

    Returns:

      uuid hex formatted string

  classmethod convert_uuid_hex_to_bytes(uuid_string)

    Compress UUID formatted strings to bytes.

    Parameters:

      uuid_string – uuid string to compress to bytes

    Returns:

      a byte representation of the uuid

  classmethod disassemble(payload)

    Disassemble a payload into the component data.

    The tuple consists of:

        (user_id, methods, expires_at_str)

    - `methods` are the auth methods.

    Parameters:

      payload – this variant of payload

    Returns:

      a tuple of the payloads component data

  classmethod random_urlsafe_str_to_bytes(s)

    Convert string from `random_urlsafe_str()` to bytes.

    Return type:

      bytes

this page last updated: 2026-04-01 20:09:17

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug