keystone.receipt.receipt_formatters 模块

class keystone.receipt.receipt_formatters.ReceiptFormatter[source]

基类: object

打包和解包有效载荷,以便进行传输。

create_receipt(user_id, methods, expires_at)[source]

根据一组有效载荷属性生成 Fernet 收据。

classmethod creation_time(fernet_receipt)[source]

返回有效 Fernet 收据的创建时间。

property crypto

返回一个密码学实例。

你可以通过自定义 crypto @property 来扩展此类,以提供你自己的收据编码/解码。例如,使用不同的密码学库(例如 python-keyczar)或满足任意安全要求。

此 @property 只需要返回一个实现 encrypt(plaintext)decrypt(ciphertext) 的对象。

pack(payload)[source]

将有效载荷打包成收据进行传输。

返回类型:

str

classmethod restore_padding(receipt)[source]

根据收据大小恢复填充。

参数:

receipt (str) – 要恢复填充的收据

返回值:

带有正确填充的收据

unpack(receipt)[source]

解包收据并验证有效载荷。

返回类型:

bytes

validate_receipt(receipt)[source]

验证 Fernet 收据并返回有效载荷属性。

class keystone.receipt.receipt_formatters.ReceiptPayload[source]

基类: object

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

组装收据的有效载荷。

参数:
  • user_id – 收据请求中的用户标识符

  • methods – 使用的身份验证方法列表

  • expires_at – 收据的到期时间

返回值:

收据的有效载荷

classmethod attempt_convert_uuid_hex_to_bytes(value)[source]

尝试将值转换为字节或返回该值。

参数:

value – 要尝试转换为字节的值

返回值:

包含一个布尔值,指示 user_id 是否存储为字节,以及 uuid 值是否为字节,或者原始值

classmethod base64_encode(s)[source]

编码一个 URL 安全的字符串。

返回类型:

str

classmethod convert_uuid_bytes_to_hex(uuid_byte_string)[source]

根据字节字符串生成 uuid.hex 格式。

参数:

uuid_byte_string – 要生成的 uuid 字符串

返回值:

uuid hex 格式化的字符串

classmethod convert_uuid_hex_to_bytes(uuid_string)[source]

将 UUID 格式化的字符串压缩为字节。

参数:

uuid_string – 要压缩为字节的 uuid 字符串

返回值:

uuid 的字节表示形式

classmethod disassemble(payload)[source]

将有效载荷解组为组件数据。

该元组由

(user_id, methods, expires_at_str)
  • methods 是身份验证方法。

参数:

payload – 这种变体的有效载荷

返回值:

有效载荷组件数据的元组

classmethod random_urlsafe_str_to_bytes(s)[source]

将来自 random_urlsafe_str() 的字符串转换为字节。

返回类型:

bytes