Repository: pypi/warehouse

Issue:
Replace md5 with sha256 on UI
Since PyPI is being rewritten, it's a good opportunity to replace md5 hashes with sha256.

NOTE: there is also #681 which talks about the upload functionality related to md5



Discussion:
It's planned to do that yes. It requires a bit of work to migrate everything because we have to loop over _all_ of the current packages and recompute their hashes.


Resolving patch:
diff --git a/warehouse/legacy/api/json.py b/warehouse/legacy/api/json.py
--- a/warehouse/legacy/api/json.py
+++ b/warehouse/legacy/api/json.py
@@ -124,6 +124,10 @@ def json_release(release, request):
                 "has_sig": f.has_signature,
                 "comment_text": f.comment_text,
                 "md5_digest": f.md5_digest,
+                "digests": {
+                    "md5": f.md5_digest,
+                    "sha256": f.sha256_digest,
+                },
                 "size": f.size,
                 "downloads": f.downloads,
                 "upload_time": f.upload_time.strftime("%Y-%m-%dT%H:%M:%S"),
diff --git a/warehouse/legacy/api/xmlrpc.py b/warehouse/legacy/api/xmlrpc.py
--- a/warehouse/legacy/api/xmlrpc.py
+++ b/warehouse/legacy/api/xmlrpc.py
@@ -238,6 +238,10 @@ def release_urls(request, package_name, version):
             "python_version": f.python_version,
             "size": f.size,
             "md5_digest": f.md5_digest,
+            "digests": {
+                "md5": f.md5_digest,
+                "sha256": f.sha256_digest,
+            },
             "has_sig": f.has_signature,
             "upload_time": f.upload_time,
             "comment_text": f.comment_text,


Test patch:
diff --git a/tests/unit/legacy/api/test_json.py b/tests/unit/legacy/api/test_json.py
--- a/tests/unit/legacy/api/test_json.py
+++ b/tests/unit/legacy/api/test_json.py
@@ -185,6 +185,10 @@ def test_detail_renders(self, pyramid_config, db_request):
                         "filename": files[0].filename,
                         "has_sig": True,
                         "md5_digest": files[0].md5_digest,
+                        "digests": {
+                            "md5": files[0].md5_digest,
+                            "sha256": files[0].sha256_digest,
+                        },
                         "packagetype": None,
                         "python_version": "source",
                         "size": 200,
@@ -201,6 +205,10 @@ def test_detail_renders(self, pyramid_config, db_request):
                         "filename": files[1].filename,
                         "has_sig": True,
                         "md5_digest": files[1].md5_digest,
+                        "digests": {
+                            "md5": files[1].md5_digest,
+                            "sha256": files[1].sha256_digest,
+                        },
                         "packagetype": None,
                         "python_version": "source",
                         "size": 200,
@@ -219,6 +227,10 @@ def test_detail_renders(self, pyramid_config, db_request):
                     "filename": files[1].filename,
                     "has_sig": True,
                     "md5_digest": files[1].md5_digest,
+                    "digests": {
+                        "md5": files[1].md5_digest,
+                        "sha256": files[1].sha256_digest,
+                    },
                     "packagetype": None,
                     "python_version": "source",
                     "size": 200,
diff --git a/tests/unit/legacy/api/test_xmlrpc.py b/tests/unit/legacy/api/test_xmlrpc.py
--- a/tests/unit/legacy/api/test_xmlrpc.py
+++ b/tests/unit/legacy/api/test_xmlrpc.py
@@ -373,6 +373,10 @@ def test_release_urls(db_request):
             "python_version": file_.python_version,
             "size": file_.size,
             "md5_digest": file_.md5_digest,
+            "digests": {
+                "md5": file_.md5_digest,
+                "sha256": file_.sha256_digest,
+            },
             "has_sig": file_.has_signature,
             "upload_time": file_.upload_time,
             "comment_text": file_.comment_text,