@@ -268,29 +268,29 @@ def get_config_hash(step: Entity):
268
268
269
269
270
270
def hash_object (obj ) -> str :
271
- """Get the MD5 hash of an object.
271
+ """Get the SHA256 hash of an object.
272
272
273
273
Args:
274
274
obj (dict): The object
275
275
Returns:
276
- str: The MD5 hash of the object
276
+ str: The SHA256 hash of the object
277
277
"""
278
- return hashlib .md5 (str (obj ).encode ()).hexdigest ()
278
+ return hashlib .sha256 (str (obj ).encode ()).hexdigest ()
279
279
280
280
281
281
def hash_file (path : str ) -> str :
282
- """Get the MD5 hash of a file.
282
+ """Get the SHA256 hash of a file.
283
283
284
284
Args:
285
285
path (str): The local path for the file.
286
286
Returns:
287
- str: The MD5 hash of the file.
287
+ str: The SHA256 hash of the file.
288
288
"""
289
- return _hash_file (path , hashlib .md5 ()).hexdigest ()
289
+ return _hash_file (path , hashlib .sha256 ()).hexdigest ()
290
290
291
291
292
292
def hash_files_or_dirs (paths : List [str ]) -> str :
293
- """Get the MD5 hash of the contents of a list of files or directories.
293
+ """Get the SHA256 hash of the contents of a list of files or directories.
294
294
295
295
Hash is changed if:
296
296
* input list is changed
@@ -301,58 +301,58 @@ def hash_files_or_dirs(paths: List[str]) -> str:
301
301
Args:
302
302
paths: List of file or directory paths
303
303
Returns:
304
- str: The MD5 hash of the list of files or directories.
304
+ str: The SHA256 hash of the list of files or directories.
305
305
"""
306
- md5 = hashlib .md5 ()
306
+ sha256 = hashlib .sha256 ()
307
307
for path in sorted (paths ):
308
- md5 = _hash_file_or_dir (path , md5 )
309
- return md5 .hexdigest ()
308
+ sha256 = _hash_file_or_dir (path , sha256 )
309
+ return sha256 .hexdigest ()
310
310
311
311
312
- def _hash_file_or_dir (path : str , md5 : Hash ) -> Hash :
312
+ def _hash_file_or_dir (path : str , sha256 : Hash ) -> Hash :
313
313
"""Updates the inputted Hash with the contents of the current path.
314
314
315
315
Args:
316
316
path: path of file or directory
317
317
Returns:
318
- str: The MD5 hash of the file or directory
318
+ str: The SHA256 hash of the file or directory
319
319
"""
320
320
if isinstance (path , str ) and path .lower ().startswith ("file://" ):
321
321
path = unquote (urlparse (path ).path )
322
- md5 .update (path .encode ())
322
+ sha256 .update (path .encode ())
323
323
if Path (path ).is_dir ():
324
- md5 = _hash_dir (path , md5 )
324
+ sha256 = _hash_dir (path , sha256 )
325
325
elif Path (path ).is_file ():
326
- md5 = _hash_file (path , md5 )
327
- return md5
326
+ sha256 = _hash_file (path , sha256 )
327
+ return sha256
328
328
329
329
330
- def _hash_dir (directory : Union [str , Path ], md5 : Hash ) -> Hash :
330
+ def _hash_dir (directory : Union [str , Path ], sha256 : Hash ) -> Hash :
331
331
"""Updates the inputted Hash with the contents of the current path.
332
332
333
333
Args:
334
334
directory: path of the directory
335
335
Returns:
336
- str: The MD5 hash of the directory
336
+ str: The SHA256 hash of the directory
337
337
"""
338
338
if not Path (directory ).is_dir ():
339
339
raise ValueError (str (directory ) + " is not a valid directory" )
340
340
for path in sorted (Path (directory ).iterdir ()):
341
- md5 .update (path .name .encode ())
341
+ sha256 .update (path .name .encode ())
342
342
if path .is_file ():
343
- md5 = _hash_file (path , md5 )
343
+ sha256 = _hash_file (path , sha256 )
344
344
elif path .is_dir ():
345
- md5 = _hash_dir (path , md5 )
346
- return md5
345
+ sha256 = _hash_dir (path , sha256 )
346
+ return sha256
347
347
348
348
349
- def _hash_file (file : Union [str , Path ], md5 : Hash ) -> Hash :
349
+ def _hash_file (file : Union [str , Path ], sha256 : Hash ) -> Hash :
350
350
"""Updates the inputted Hash with the contents of the current path.
351
351
352
352
Args:
353
353
file: path of the file
354
354
Returns:
355
- str: The MD5 hash of the file
355
+ str: The SHA256 hash of the file
356
356
"""
357
357
if isinstance (file , str ) and file .lower ().startswith ("file://" ):
358
358
file = unquote (urlparse (file ).path )
@@ -363,8 +363,8 @@ def _hash_file(file: Union[str, Path], md5: Hash) -> Hash:
363
363
data = f .read (BUF_SIZE )
364
364
if not data :
365
365
break
366
- md5 .update (data )
367
- return md5
366
+ sha256 .update (data )
367
+ return sha256
368
368
369
369
370
370
def validate_step_args_input (
0 commit comments