monkey-patch _digest for fips

This commit is contained in:
adamscmRH 2018-11-08 17:08:12 -05:00 committed by Ryan Petrello
parent 36faaf4720
commit 8d012de3e2
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -21,6 +21,32 @@ except ImportError: # pragma: no cover
MODE = 'production'
import hashlib
from django.utils.encoding import force_bytes
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.backends.base import schema
class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor):
@classmethod
def _digest(cls, *args):
"""
Generates a 32-bit digest of a set of arguments that can be used to
shorten identifying names.
"""
try:
h = hashlib.md5()
except ValueError:
h = hashlib.md5(usedforsecurity=False)
for arg in args:
h.update(force_bytes(arg))
return h.hexdigest()[:8]
schema.BaseDatabaseSchemaEditor = FipsBaseDatabaseSchemaEditor
def find_commands(management_dir):
# Modified version of function from django/core/management/__init__.py.
command_dir = os.path.join(management_dir, 'commands')