Skip to content

Commit cd51e4d

Browse files
committed
- fix issue "TypeError: Expected instance of hashes.HashAlgorithm."
- removed backend because PBKDF2HMAC no longer needs or uses it
1 parent ce8127c commit cd51e4d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

django_cryptography/conf.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from typing import Any, Dict
22

33
from appconf import AppConf
4-
from cryptography.hazmat.backends import default_backend
54
from cryptography.hazmat.primitives import hashes
65
from cryptography.hazmat.primitives.kdf import pbkdf2
76
from django.conf import settings
87
from django.utils.encoding import force_bytes
98

109

1110
class CryptographyConf(AppConf):
12-
BACKEND = default_backend()
1311
DIGEST = hashes.SHA256()
1412
KEY = None
1513
SALT = "django-cryptography"
@@ -22,16 +20,14 @@ def configure_salt(self, value: Any) -> bytes:
2220
return force_bytes(value)
2321

2422
def configure(self) -> Dict[str, Any]:
25-
backend = self.configured_data["BACKEND"]
26-
digest = self.configured_data["DIGEST"]
23+
digest = self.configured_data["DIGEST"]()
2724
salt = self.configured_data["SALT"]
2825
# Key Derivation Function
2926
kdf = pbkdf2.PBKDF2HMAC(
3027
algorithm=digest,
3128
length=digest.digest_size,
3229
salt=salt,
3330
iterations=30000,
34-
backend=backend,
3531
)
3632
self.configured_data["KEY"] = kdf.derive(
3733
force_bytes(self.configured_data["KEY"] or settings.SECRET_KEY)

0 commit comments

Comments
 (0)