Tools related to symmetric ciphers

Cryptography backend specific templates and tools for symmetric ciphers.

class pyflocker.ciphers.backends.cryptography_.symmetric.NonAEADCipherTemplate[source]

Bases: BaseNonAEADCipher

Template class to provide the default behavior if BaseNonAEADCipher.

Subclasses need to provide:
  • _encrypting

  • _ctx

is_encrypting() bool[source]

Whether the cipher is encrypting or not.

Returns:

True if encrypting, else False.

update(data: bytes) bytes[source]

Takes bytes-like object and returns encrypted/decrypted bytes object.

Parameters:

data – The bytes-like object to pass to the cipher.

Returns:

Encrypted/decrypted data as bytes.

update_into(data: bytes, out: bytearray | memoryview) None[source]

Encrypt or decrypt the data and store it in a preallocated buffer out.

Parameters:
  • data – The bytes-like object to pass to the cipher.

  • out – The buffer interface where the encrypted/decrypted data must be written into.

finalize() None[source]

Finalizes and closes the cipher.

Raises:

AlreadyFinalized – If the cipher was already finalized.

class pyflocker.ciphers.backends.cryptography_.symmetric.AuthenticationMixin[source]

Bases: object

Mixin class to provide authentication behavior to ciphers.

Classes inheriting this must provide these attributes:

_updated

A boolean indicating whether update() method of _cipher was called.

Type:

bool

_ctx

A cipher context from cryptography package that has finalize() method.

Type:

Any

_tag

A byte sequence denoting the MAC tag generated by the cipher after encryption.

Type:

bytes | None

is_encrypting: Callable
authenticate(data: bytes) None[source]
finalize(tag: bytes | None = None) None[source]
calculate_tag() bytes | None[source]
class pyflocker.ciphers.backends.cryptography_.symmetric.AEADCipherTemplate[source]

Bases: AuthenticationMixin, BaseAEADCipher

Template class to provide the default behavior of BaseAEADCipher.

Subclasses need to provide the following attributes:
  • _encrypting

  • _ctx

is_encrypting() bool[source]

Whether the cipher is encrypting or not.

Returns:

True if encrypting, else False.

update(data: bytes) bytes[source]

Takes bytes-like object and returns encrypted/decrypted bytes object.

Parameters:

data – The bytes-like object to pass to the cipher.

Returns:

Encrypted/decrypted data as bytes.

update_into(data: bytes, out: bytearray | memoryview) None[source]

Encrypt or decrypt the data and store it in a preallocated buffer out.

Parameters:
  • data – The bytes-like object to pass to the cipher.

  • out – The buffer interface where the encrypted/decrypted data must be written into.