1 | """
|
---|
2 | This module contains helper functions for dealing with hash algorithms.
|
---|
3 | this was written to "uncouple" other modules from the actual algorithms used.
|
---|
4 | can be changed through the settings variable FAVORITE_HASH_ALGO.
|
---|
5 |
|
---|
6 | currently used from the algorithms' interfaces:
|
---|
7 | * hash.new("some string").hexdigest()
|
---|
8 | returns a hexdigest for the given string, used in:
|
---|
9 | * django/contrib/sessions/models.py
|
---|
10 | * django/contrib/admin/views/decorators.py
|
---|
11 | * hash.digest_size
|
---|
12 | returns the digest_size (REMEMBER: hexdigest is twice as long), used in:
|
---|
13 | * django/contrib/sessions/models.py
|
---|
14 | * django/contrib/admin/views/decorators.py
|
---|
15 | """
|
---|
16 | from django.conf import settings
|
---|
17 |
|
---|
18 | DEFAULT_HASH_ALGO="md5"
|
---|
19 | KNOWN_HASH_ALGOS=["md5", "sha"]
|
---|
20 |
|
---|
21 | def _verify_hash_algo(algo):
|
---|
22 | """ TODO: the verification of the hash algos is _way_ too simple..
|
---|
23 | """
|
---|
24 | if not algo in KNOWN_HASH_ALGOS:
|
---|
25 | algo = DEFAULT_HASH_ALGO
|
---|
26 | return algo
|
---|
27 |
|
---|
28 | # TODO: a global variable is not really the nicest way :(
|
---|
29 | _algo = _verify_hash_algo(settings.FAVORITE_HASH_ALGO)
|
---|
30 |
|
---|
31 | if _algo == "md5":
|
---|
32 | import md5 as hash
|
---|
33 | elif _algo == "sha":
|
---|
34 | import sha as hash
|
---|