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.

pydantic model encommon.crypts.params.CryptParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "CryptParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "phrase": {
         "description": "Passphrase for the operations",
         "minLength": 1,
         "title": "Phrase",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "phrase"
   ]
}

Config:
  • extra: str = forbid

Fields:
field phrase: Annotated[str, FieldInfo(annotation=NoneType, required=True, description='Passphrase for the operations', metadata=[MinLen(min_length=1)])] [Required]#

Passphrase for the operations

Constraints:
  • min_length = 1

pydantic model encommon.crypts.params.CryptsParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "CryptsParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "phrases": {
         "additionalProperties": {
            "$ref": "#/$defs/CryptParams"
         },
         "description": "Passphrases for the operations",
         "minProperties": 0,
         "title": "Phrases",
         "type": "object"
      }
   },
   "$defs": {
      "CryptParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrase": {
               "description": "Passphrase for the operations",
               "minLength": 1,
               "title": "Phrase",
               "type": "string"
            }
         },
         "required": [
            "phrase"
         ],
         "title": "CryptParams",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "phrases"
   ]
}

Config:
  • extra: str = forbid

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

Passphrases for the operations

Constraints:
  • 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.

pydantic model encommon.crypts.CryptsParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "CryptsParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "phrases": {
         "additionalProperties": {
            "$ref": "#/$defs/CryptParams"
         },
         "description": "Passphrases for the operations",
         "minProperties": 0,
         "title": "Phrases",
         "type": "object"
      }
   },
   "$defs": {
      "CryptParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrase": {
               "description": "Passphrase for the operations",
               "minLength": 1,
               "title": "Phrase",
               "type": "string"
            }
         },
         "required": [
            "phrase"
         ],
         "title": "CryptParams",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "phrases"
   ]
}

Config:
  • extra: str = forbid

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

Passphrases for the operations

Constraints:
  • 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.