From 84adf5e3bc19f42b9687b6adcb8fb14bd43595f9 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 15 Dec 2020 14:39:44 -0800 Subject: [PATCH] Remove md5_factory function ...because otherwise I'll find myself wanting to just use it *everywhere*, which seems to defeat the purpose. Change-Id: I88c7a9fb78890302bb71aeaf63ad587e59767726 --- swift/common/utils.py | 4 ---- swift/obj/diskfile.py | 4 ++-- swift/proxy/controllers/obj.py | 6 +++--- test/unit/common/middleware/s3api/test_s3request.py | 8 ++++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index 908096e00d..bf5d9d4f3b 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -4882,10 +4882,6 @@ except TypeError: return hashlib.md5(string) # nosec -def md5_factory(): - return md5(usedforsecurity=False) - - class ShardRange(object): """ A ShardRange encapsulates sharding state related to a container including diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index 0bb157d866..893f1c5047 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -66,7 +66,7 @@ from swift.common.utils import mkdirs, Timestamp, \ get_md5_socket, F_SETPIPE_SZ, decode_timestamps, encode_timestamps, \ MD5_OF_EMPTY_STRING, link_fd_to_path, \ O_TMPFILE, makedirs_count, replace_partition_in_path, remove_directory, \ - md5, md5_factory + md5 from swift.common.splice import splice, tee from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \ DiskFileCollision, DiskFileNoSpace, DiskFileDeviceUnavailable, \ @@ -1116,7 +1116,7 @@ class BaseDiskFileManager(object): :param policy: storage policy used """ if six.PY2: - hashes = defaultdict(md5_factory) + hashes = defaultdict(lambda: md5(usedforsecurity=False)) else: class shim(object): def __init__(self): diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index 549245a44c..136e553d43 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -48,8 +48,7 @@ from swift.common.utils import ( GreenAsyncPile, GreenthreadSafeIterator, Timestamp, WatchdogTimeout, normalize_delete_at_timestamp, public, get_expirer_container, document_iters_to_http_response_body, parse_content_range, - quorum_size, reiterate, close_if_possible, safe_json_loads, md5, - md5_factory) + quorum_size, reiterate, close_if_possible, safe_json_loads, md5) from swift.common.bufferedhttp import http_connect from swift.common.constraints import check_metadata, check_object_creation from swift.common import constraints @@ -3179,7 +3178,8 @@ class ECObjectController(BaseObjectController): bytes_transferred = 0 chunk_transform = chunk_transformer(policy) chunk_transform.send(None) - frag_hashers = collections.defaultdict(md5_factory) + frag_hashers = collections.defaultdict( + lambda: md5(usedforsecurity=False)) def send_chunk(chunk): # Note: there's two different hashers in here. etag_hasher is diff --git a/test/unit/common/middleware/s3api/test_s3request.py b/test/unit/common/middleware/s3api/test_s3request.py index bad3a9edeb..5854ef2bf1 100644 --- a/test/unit/common/middleware/s3api/test_s3request.py +++ b/test/unit/common/middleware/s3api/test_s3request.py @@ -32,7 +32,7 @@ from swift.common.middleware.s3api.s3request import S3Request, \ from swift.common.middleware.s3api.s3response import InvalidArgument, \ NoSuchBucket, InternalError, \ AccessDenied, SignatureDoesNotMatch, RequestTimeTooSkewed -from swift.common.utils import md5, md5_factory +from swift.common.utils import md5 from test.unit import DebugLogger @@ -825,7 +825,7 @@ class TestHashingInput(S3ApiTestCase): def test_good(self): raw = b'123456789' wrapped = HashingInput( - BytesIO(raw), 9, md5_factory, + BytesIO(raw), 9, lambda: md5(usedforsecurity=False), md5(raw, usedforsecurity=False).hexdigest()) self.assertEqual(b'1234', wrapped.read(4)) self.assertEqual(b'56', wrapped.read(2)) @@ -851,7 +851,7 @@ class TestHashingInput(S3ApiTestCase): def test_too_long(self): raw = b'123456789' wrapped = HashingInput( - BytesIO(raw), 8, md5_factory, + BytesIO(raw), 8, lambda: md5(usedforsecurity=False), md5(raw, usedforsecurity=False).hexdigest()) self.assertEqual(b'1234', wrapped.read(4)) self.assertEqual(b'56', wrapped.read(2)) @@ -865,7 +865,7 @@ class TestHashingInput(S3ApiTestCase): def test_too_short(self): raw = b'123456789' wrapped = HashingInput( - BytesIO(raw), 10, md5_factory, + BytesIO(raw), 10, lambda: md5(usedforsecurity=False), md5(raw, usedforsecurity=False).hexdigest()) self.assertEqual(b'1234', wrapped.read(4)) self.assertEqual(b'56', wrapped.read(2))