Skip to content

Commit 3c6449e

Browse files
Switched from md5 to sha256 and updated corresponding tests.
1 parent 92bff67 commit 3c6449e

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

elastic_datashader/drawing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import lru_cache
2-
from hashlib import md5
2+
from hashlib import sha256
33
from typing import Dict, Iterable, Tuple
44

55
import io
@@ -23,7 +23,7 @@ def get_categorical_color_index(category: str, num_colors: int) -> int:
2323
across independent tile generations, but can result in situations where
2424
colors are reused before exhausting the color palette.
2525
"""
26-
category_hash = md5(bytes(category, encoding="utf-8")).hexdigest()
26+
category_hash = sha256(bytes(category, encoding="utf-8")).hexdigest()
2727
number = int(category_hash[0:2], 16)
2828
return number % num_colors
2929

elastic_datashader/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime, timedelta, timezone
2-
from hashlib import md5
2+
from hashlib import sha256
33
from json import loads
44
from socket import gethostname
55
from time import sleep
@@ -244,7 +244,7 @@ def get_time_bounds(now: datetime, from_time: Optional[str], to_time: Optional[s
244244

245245
def get_parameter_hash(params: Dict[str, Any]) -> str:
246246
"""Calculates a hash value for the specific parameter set"""
247-
parameter_hash = md5()
247+
parameter_hash = sha256()
248248

249249
for _, p in sorted(params.items()):
250250
if isinstance(p, datetime):

tests/test_drawing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
(
1414
("foo", "bar", "baz", "Other", "N/A"),
1515
{
16-
"bar": "#8a9500",
17-
"baz": "#870062",
18-
"foo": "#9a0390",
16+
"bar": "#b5e2e1",
17+
"baz": "#672138",
18+
"foo": "#bfebc3",
1919
"Other": "#AAAAAA",
2020
"N/A": "#666666",
2121
}
@@ -84,7 +84,7 @@ def test_ellipse_planar_points():
8484
np.testing.assert_almost_equal(actual_x[8], 0)
8585
np.testing.assert_almost_equal(actual_x[12], -50)
8686

87-
87+
8888

8989
radm = 100
9090
radn = 30

tests/test_parameters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def test_get_category_field():
119119
assert parameters.get_category_field("banana") == "banana"
120120

121121
def test_get_parameter_hash():
122-
assert parameters.get_parameter_hash({"foo": "bar", "baz": 1}) == "0d922e38f1a94fdc8acc6016c333d49e"
123-
assert parameters.get_parameter_hash({"foo": "bar", "baz": 1, "abc": datetime(2022, 2, 17, 11, 0, 0, tzinfo=timezone.utc)}) == "5463c0e1ae7f3c9e182afc2786050765"
124-
assert parameters.get_parameter_hash({}) == "d41d8cd98f00b204e9800998ecf8427e"
122+
assert parameters.get_parameter_hash({"foo": "bar", "baz": 1}) == "a6488297eb1cdaa23e196800b1c399b13d9a5c86cfecaf8f9fd0fbe9af7533db"
123+
assert parameters.get_parameter_hash({"foo": "bar", "baz": 1, "abc": datetime(2022, 2, 17, 11, 0, 0, tzinfo=timezone.utc)}) == "88ade56886a8099e6fd3c25525a0fb9ab3938be64374569480ed3bfd7f3d70e9"
124+
assert parameters.get_parameter_hash({}) == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
125125

126126
def test_get_time_bounds_already_quantized():
127127
now = datetime(2022, 6, 14, 12, 15, 0, tzinfo=timezone.utc)

0 commit comments

Comments
 (0)