keystone.receipt.receipt_formatters module

class keystone.receipt.receipt_formatters.ReceiptFormatter[source]

Bases: object

Packs and unpacks payloads into receipts for transport.

create_receipt(user_id, methods, expires_at)[source]

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

classmethod creation_time(fernet_receipt)[source]

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)[source]

Pack a payload for transport as a receipt.

Return type

six.text_type

classmethod restore_padding(receipt)[source]

Restore padding based on receipt size.

Parameters

receipt (six.text_type) – receipt to restore padding on

Returns

receipt with correct padding

unpack(receipt)[source]

Unpack a receipt, and validate the payload.

Return type

six.binary_type

validate_receipt(receipt)[source]

Validate a Fernet receipt and returns the payload attributes.

class keystone.receipt.receipt_formatters.ReceiptPayload[source]

Bases: object

classmethod assemble(user_id, methods, expires_at)[source]

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)[source]

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)[source]

Encode a URL-safe string.

Return type

six.text_type

classmethod convert_uuid_bytes_to_hex(uuid_byte_string)[source]

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)[source]

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)[source]

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)[source]

Convert string from random_urlsafe_str() to six.binary_type.

Return type

six.binary_type