Skip to content

Commit

Permalink
Use canonicaljson instead of json.dumps(..., sort_keys=True) for …
Browse files Browse the repository at this point in the history
…hashing
  • Loading branch information
Wiebke committed Mar 4, 2024
1 parent 212530d commit f0d6a42
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ scipy
dash-extensions==1.0.1
dash-bootstrap-components==1.5.0
dash_auth==2.0.0
canonicaljson
6 changes: 3 additions & 3 deletions utils/annotations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import hashlib
import io
import json
import zipfile

import canonicaljson
import numpy as np
import scipy.sparse as sp
from matplotlib.path import Path
Expand Down Expand Up @@ -62,8 +62,8 @@ def get_annotation_classes(self):

def get_annotations_hash(self):
hash_object = hashlib.md5()
hash_object.update(json.dumps(self.annotations, sort_keys=True).encode())
hash_object.update(json.dumps(self.annotation_classes, sort_keys=True).encode())
hash_object.update(canonicaljson.encode_canonical_json(self.annotations))
hash_object.update(canonicaljson.encode_canonical_json(self.annotation_classes))
return hash_object.hexdigest()

def get_annotation_mask_as_bytes(self):
Expand Down

0 comments on commit f0d6a42

Please sign in to comment.