encommon.crypts package#

Subpackages#

Submodules#

encommon.crypts.crypts module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.crypts.crypts.Crypts(params: CryptsParams | None = None)[source]#

Bases: object

Encrypt and decrypt values using passphrase dictionary.

Example#

>>> phrase = Crypts.keygen()
>>> source = {'default': {'phrase': phrase}}
>>> params = CryptsParams(phrases=source)
>>> crypts = Crypts(params)
>>> encrypt = crypts.encrypt('example')
>>> encrypt
'$ENCRYPT;1.0;default;...
>>> crypts.decrypt(encrypt)
'example'
param params:

Parameters used to instantiate the class.

create(unique: str, params: CryptParams) None[source]#

Create a new phrase using the provided input parameters.

Parameters:
  • unique – Unique identifier of mapping passphrase.

  • params – Parameters used to instantiate the class.

decrypt(value: str) str[source]#

Decrypt the provided value with the relevant passphrase.

Parameters:

value – String value that will returned decrypted.

Returns:

Decrypted value using the relevant passphrase.

delete(unique: str) None[source]#

Delete the phrase from the internal dictionary reference.

Parameters:

unique – Unique identifier of mapping passphrase.

encrypt(value: str, unique: str = 'default') str[source]#

Encrypt the provided value with the relevant passphrase.

Parameters:
  • value – String value that will returned encrypted.

  • unique – Unique identifier of mapping passphrase.

Returns:

Encrypted value using the relevant passphrase.

classmethod keygen() str[source]#

Return new randomly generated Fernet key for passphrase.

Returns:

Randomly generated Fernet key for passphrase.

property params: CryptsParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

encommon.crypts.crypts.crypt_clean(value: str) str[source]#

Return the parsed and normalized encrypted string value.

Parameters:

value – String value that will returned decrypted.

Returns:

Parsed and normalized encrypted string value.

encommon.crypts.hashes module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.crypts.hashes.Hashes(string: str)[source]#

Bases: object

Create hash values using the provided at instantiation.

Example#

>>> hashes = Hashes('string')
>>> hashes.sha256
'473287f8298dba7163a897908958f7c0ea...

Example#

>>> hashes = Hashes('string')
>>> hashes.uuid
'38ffd1ed-2b4d-3c84-ae45-bf3bf354eee4'
param string:

String which will be used within hashing.

property apache: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property md5: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha1: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha256: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha512: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property string: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property uuid: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

encommon.crypts.params module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.crypts.params.CryptParams(phrase: str)[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

model_config = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

phrase: Annotated[str, FieldInfo(annotation=NoneType, required=True, description='Passphrase for the operations', metadata=[MinLen(min_length=1)])]#
class encommon.crypts.params.CryptsParams(phrases: dict[str, CryptParams] | None = None)[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

model_config = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

phrases: Annotated[dict[str, CryptParams], FieldInfo(annotation=NoneType, required=True, description='Passphrases for the operations', metadata=[MinLen(min_length=0)])]#

Module contents#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.crypts.Crypts(params: CryptsParams | None = None)[source]#

Bases: object

Encrypt and decrypt values using passphrase dictionary.

Example#

>>> phrase = Crypts.keygen()
>>> source = {'default': {'phrase': phrase}}
>>> params = CryptsParams(phrases=source)
>>> crypts = Crypts(params)
>>> encrypt = crypts.encrypt('example')
>>> encrypt
'$ENCRYPT;1.0;default;...
>>> crypts.decrypt(encrypt)
'example'
param params:

Parameters used to instantiate the class.

create(unique: str, params: CryptParams) None[source]#

Create a new phrase using the provided input parameters.

Parameters:
  • unique – Unique identifier of mapping passphrase.

  • params – Parameters used to instantiate the class.

decrypt(value: str) str[source]#

Decrypt the provided value with the relevant passphrase.

Parameters:

value – String value that will returned decrypted.

Returns:

Decrypted value using the relevant passphrase.

delete(unique: str) None[source]#

Delete the phrase from the internal dictionary reference.

Parameters:

unique – Unique identifier of mapping passphrase.

encrypt(value: str, unique: str = 'default') str[source]#

Encrypt the provided value with the relevant passphrase.

Parameters:
  • value – String value that will returned encrypted.

  • unique – Unique identifier of mapping passphrase.

Returns:

Encrypted value using the relevant passphrase.

classmethod keygen() str[source]#

Return new randomly generated Fernet key for passphrase.

Returns:

Randomly generated Fernet key for passphrase.

property params: CryptsParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

class encommon.crypts.CryptsParams(phrases: dict[str, CryptParams] | None = None)[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

model_config = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

phrases: Annotated[dict[str, CryptParams], FieldInfo(annotation=NoneType, required=True, description='Passphrases for the operations', metadata=[MinLen(min_length=0)])]#
class encommon.crypts.Hashes(string: str)[source]#

Bases: object

Create hash values using the provided at instantiation.

Example#

>>> hashes = Hashes('string')
>>> hashes.sha256
'473287f8298dba7163a897908958f7c0ea...

Example#

>>> hashes = Hashes('string')
>>> hashes.uuid
'38ffd1ed-2b4d-3c84-ae45-bf3bf354eee4'
param string:

String which will be used within hashing.

property apache: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property md5: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha1: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha256: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha512: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property string: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property uuid: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.