diff --git a/cacheops/utils.py b/cacheops/utils.py index cd71c6ea..4857f262 100644 --- a/cacheops/utils.py +++ b/cacheops/utils.py @@ -1,6 +1,7 @@ import re import json import inspect +import sys from funcy import memoize, compose, wraps, any, any_fn, select_values, mapcat from django.db import models @@ -143,7 +144,16 @@ def repl(m): class md5: def __init__(self, s=None): - self.md5 = hashlib.md5() + md5_kwargs = {} + + # set usedforsecurity for FIPS compliance + # usedforsecurity was introduced in 3.9 + # this is for backwards compatibility + pyversion = sys.version_info + if (pyversion.major == 3 and pyversion.minor >= 9) or pyversion.major > 3: + md5_kwargs["usedforsecurity"] = False + + self.md5 = hashlib.md5(**md5_kwargs) if s is not None: self.update(s)