Encryption Field Reference#

Two classes used for denoting which fields to hash / encrypt

class alaric.encryption.HashedFields(*fields: str)#

A list of fields which should be hashed when encountered.

Due to the nature of hashing, this is a one way operation and is only done when sending items to Mongo.

Note

Take care not to pass the hashed output back to a method which sends data to Mongo as it will result in it being re-hashed.

If this is the case, tell the document method to ignore processing the field.

1from alaric.encryption import HashedFields
2
3HashedFields("guild_id", "test")
class alaric.encryption.AutomaticHashedFields(*fields: str)#

A list of fields which should have a hashed field created automatically in the background but without access to the user.

I.e. Alaric when told to automatically hash the field guild_id will look at incoming data, create an extra field called guild_id_hashed and add it to the database. Whenever you fetch data from the database, Alaric will remove this field so you never see it.

If you want to use this field in your code, use alaric.encryption.HashedFields instead.

1from alaric.encryption import AutomaticHashedFields
2
3AutomaticHashedFields("guild_id", "test")

Note

You can use this in conjunction with an encrypted field to have a hash representing the unencrypted data.

class alaric.encryption.EncryptedFields(*fields: str)#

A list of fields which should be encrypted when encountered.

1from alaric.encryption import EncryptedFields
2
3EncryptedFields("guild_id", "test")
class alaric.encryption.HashedQueryField(entry: ComparisonT)#

Use this to query against hashed fields.

This class exposes an alias HQF for shorter usage.

from alaric import AQ
from alaric.comparison import EQ
from alaric.encryption import HQF

query = AQ(HQF(EQ("_id", 1)))
build() Dict[str, Dict[str, int | str | float | bytes | dict | ObjectId]]#

Return this instance as a usable Mongo filter.

alaric.util.hash_field(field, value)#

Hash a field with SHA512

Parameters:
  • field (str) – The name of the field your hashing

  • value – The value to hash

Raises:

ValueError – Unsupported type to hash