Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Supported hash based fields are:
using the `sha512` algorithm.

`TextHMACField` is hashed in the database using the `hmac` pgcrypto function
using a key and the `sha512` algorithm. This is similar to the digest version however
using `settings.PGCRYPTO_KEY` for the key and the `sha512` algorithm. This is similar to the digest version however
the hash can only be recalculated knowing the key. This prevents someone from altering
the data and also changing the hash to match.

Expand Down
8 changes: 4 additions & 4 deletions pgcrypto/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class TextDigestField(HashMixin, models.TextField):
"""Text digest field for postgres."""
encrypt_sql = DIGEST_SQL

def get_encrypt_sql(self, connection):
"""Get encrypt sql."""
return self.encrypt_sql.format(get_setting(connection, 'PGCRYPTO_KEY'))


TextDigestField.register_lookup(HashLookup)

Expand All @@ -34,6 +30,10 @@ class TextHMACField(HashMixin, models.TextField):
"""Text HMAC field for postgres."""
encrypt_sql = HMAC_SQL

def get_encrypt_sql(self, connection):
"""Get encrypt sql."""
return self.encrypt_sql.format(get_setting(connection, 'PGCRYPTO_KEY'))


TextHMACField.register_lookup(HashLookup)

Expand Down