Skip to content

Commit

Permalink
Merge branch 'mr/cardao/add-sha512-support' into 'master'
Browse files Browse the repository at this point in the history
Add sha512 support

See merge request it/e3-core!78
  • Loading branch information
leocardao committed Dec 11, 2024
2 parents b5723a9 + 2268505 commit a6a22b5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/e3/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HashError(e3.error.E3Error):

def __compute_hash(
path: PathLike[str] | str,
kind: Literal["md5"] | Literal["sha1"] | Literal["sha256"],
kind: Literal["md5"] | Literal["sha1"] | Literal["sha256"] | Literal["sha512"],
) -> str:
if not os.path.isfile(path):
raise HashError(kind, f"cannot find {path}")
Expand Down Expand Up @@ -64,3 +64,14 @@ def sha256(path: PathLike[str] | str) -> str:
:raise HashError: in case of error
"""
return __compute_hash(path, "sha256")


def sha512(path: PathLike[str] | str) -> str:
"""Compute sha512 hexadecimal digest of a file.
:param str path: path to a file
:return: the hash of the file content
:raise HashError: in case of error
"""
return __compute_hash(path, "sha512")

0 comments on commit a6a22b5

Please sign in to comment.