mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Use MD5 usedforsecurity=False on Python 3.9 and higher to pass FIPS
Closes #2270
This commit is contained in:
parent
5d79974186
commit
b89cac3b6a
2 changed files with 11 additions and 3 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import hashlib
|
|
||||||
import janus
|
import janus
|
||||||
import queue
|
import queue
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -15,6 +14,7 @@ from .utils import (
|
||||||
detect_spatialite,
|
detect_spatialite,
|
||||||
get_all_foreign_keys,
|
get_all_foreign_keys,
|
||||||
get_outbound_foreign_keys,
|
get_outbound_foreign_keys,
|
||||||
|
md5_not_usedforsecurity,
|
||||||
sqlite_timelimit,
|
sqlite_timelimit,
|
||||||
sqlite3,
|
sqlite3,
|
||||||
table_columns,
|
table_columns,
|
||||||
|
|
@ -74,7 +74,7 @@ class Database:
|
||||||
def color(self):
|
def color(self):
|
||||||
if self.hash:
|
if self.hash:
|
||||||
return self.hash[:6]
|
return self.hash[:6]
|
||||||
return hashlib.md5(self.name.encode("utf8")).hexdigest()[:6]
|
return md5_not_usedforsecurity(self.name)[:6]
|
||||||
|
|
||||||
def suggest_name(self):
|
def suggest_name(self):
|
||||||
if self.path:
|
if self.path:
|
||||||
|
|
|
||||||
|
|
@ -713,7 +713,7 @@ def to_css_class(s):
|
||||||
"""
|
"""
|
||||||
if css_class_re.match(s):
|
if css_class_re.match(s):
|
||||||
return s
|
return s
|
||||||
md5_suffix = hashlib.md5(s.encode("utf8")).hexdigest()[:6]
|
md5_suffix = md5_not_usedforsecurity(s)[:6]
|
||||||
# Strip leading _, -
|
# Strip leading _, -
|
||||||
s = s.lstrip("_").lstrip("-")
|
s = s.lstrip("_").lstrip("-")
|
||||||
# Replace any whitespace with hyphens
|
# Replace any whitespace with hyphens
|
||||||
|
|
@ -1401,3 +1401,11 @@ def redact_keys(original: dict, key_patterns: Iterable) -> dict:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
return redact(original)
|
return redact(original)
|
||||||
|
|
||||||
|
|
||||||
|
def md5_not_usedforsecurity(s):
|
||||||
|
try:
|
||||||
|
return hashlib.md5(s.encode("utf8"), usedforsecurity=False).hexdigest()
|
||||||
|
except TypeError:
|
||||||
|
# For Python 3.8 which does not support usedforsecurity=False
|
||||||
|
return hashlib.md5(s.encode("utf8")).hexdigest()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue