Cryptographic Structs#

Core structs#

class caterpillar.fields.Encrypted(length: int | ellipsis | _ContextLambda, algorithm: Type[CipherAlgorithm], mode: Type[Mode] | Mode, padding: Padding | Type[Padding] = None, algo_args: Iterable[_ContextLambda | Any] | None = None, mode_args: Iterable[_ContextLambda | Any] | None = None, padding_args: Iterable[_ContextLambda | Any] | None = None, post: _StructLike | None = None)[source]#

Struct that is able to encrypt/decrypt blocks of memory.

Parameters:
  • length (Union[int, _GreedyType, _ContextLambda]) – Length of the encrypted data.

  • algorithm (Type[algorithms.CipherAlgorithm]) – Encryption algorithm.

  • mode (Union[Type[modes.Mode], modes.Mode]) – Encryption mode.

  • padding (Union[Padding, Type[Padding]], optional) – Padding scheme for encryption.

  • algo_args (Optional[Iterable[_ArgType]], optional) – Additional arguments for the encryption algorithm.

  • mode_args (Optional[Iterable[_ArgType]], optional) – Additional arguments for the encryption mode.

  • padding_args (Optional[Iterable[_ArgType]], optional) – Additional arguments for the padding scheme.

  • post – Post-processing structure.

algorithm(context: _ContextLike) CipherAlgorithm[source]#

Get the encryption algorithm instance.

Parameters:

context (_ContextLike) – The current operation context.

Returns:

An instance of the encryption algorithm.

Return type:

algorithms.CipherAlgorithm

get_instance(type_: type, field: Any, args: Any, context: _ContextLambda) Any[source]#

Get an instance of a specified type.

Parameters:
  • type (type) – The desired type of the instance.

  • field (Any) – The field or instance.

  • args (Any) – Additional arguments for the instance.

  • context (_ContextLambda) – The current operation context.

Returns:

An instance of the specified type.

Return type:

Any

mode(context: _ContextLike) Mode[source]#

Get the encryption mode instance.

Parameters:

context (_ContextLike) – The current operation context.

Returns:

An instance of the encryption mode.

Return type:

modes.Mode

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single element.

Parameters:
  • obj (Any) – The element to pack.

  • context (_ContextLike) – The current operation context.

padding(context: _ContextLike) Padding[source]#

Get the padding scheme instance.

Parameters:

context (_ContextLike) – The current operation context.

Returns:

An instance of the padding scheme.

Return type:

Padding

unpack_single(context: _ContextLike) memoryview[source]#

Unpack a single element.

Parameters:

context (_ContextLike) – The current operation context.

Returns:

The unpacked element as a memoryview.

Return type:

memoryview

Standard interface#

TODO default functions