Allow configuring custom contexts by extending CryptContext
Created originally on Bitbucket by Anonymous
Besides creating custom CryptContext instances by passing the context configuration as parameters or loading it from a file:
#!python
pwd_context = CryptContext(
schemes=["pbkdf2_sha256", "des_crypt" ],
default="pbkdf2_sha256",
all__vary_rounds = 0.1,
pbkdf2_sha256__default_rounds = 8000,
)
myctx3 = CryptContext.from_path("/some/path/on/local/system")
It would be nice to allow CryptoContext configuration by overriding its fields like :
#!python
class MyCryptContext(CryptContext):
schemes = ["pbkdf2_sha256", "des_crypt"]
default_scheme = "pbkdf2_sha256"
all__vary_rounds = 0.1
pbkdf2_sha256__default_rounds = 8000
Or:
#!python
class MyCryptContext(CryptContext):
schemes = [
{
'scheme': 'pbkdf2_sha256',
'vary_rounds': 0.1
},
{
'scheme': 'des_crypt',
'default_rounds': 8000,
'vary_rounds': 0.1
}
]
And creating the instances from the subclass:
#!python
context = MyCryptContext()
I think this would be good because:
- Inherently easier to extend
- More "Pythonic" and "OOP"
- It's easier to read (IMHO)
- Doesn't rely on external configuration files and formats
- Allows adding/overriding methods (e.g. loading from and dumping to other formats while keeping full config)