mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Update calculate_blake2b_hash to use boolean comparison rather than string
Change output_format parameter from a string to boolean output_as_bytes for comparison efficiency. Default behavior will still output a hex string.
This commit is contained in:
parent
f3db713f27
commit
74787b51ba
@ -152,13 +152,15 @@ class FileHelpers:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate_blake2b_hash(
|
def calculate_blake2b_hash(
|
||||||
value_to_hash: pathlib.Path | bytes, output_format: str = "hex"
|
value_to_hash: pathlib.Path | bytes, output_as_bytes: bool = False
|
||||||
) -> str or bytes:
|
) -> str or bytes:
|
||||||
"""
|
"""
|
||||||
Calculates blake2b hash from either file at specified Path, or from supplied
|
Calculates blake2b hash from either file at specified Path, or from supplied
|
||||||
bytes. Output will either be a hex string or bytes. Hex string is the default.
|
bytes. Output will either be a hex string or bytes. Hex string is the default.
|
||||||
|
|
||||||
:param value_to_hash: Path to file or bytes to hash.
|
:param value_to_hash: Path to file or bytes to hash.
|
||||||
:param output_format: Output format, "hex" for hex in str, "bytes" for bytes.
|
:param output_as_bytes: Boolean to output as bytes. Defaults to False.
|
||||||
|
Otherwise, will output as hex string.
|
||||||
output. Defaults to "hex".
|
output. Defaults to "hex".
|
||||||
:return: blake2b hash string or bytes.
|
:return: blake2b hash string or bytes.
|
||||||
"""
|
"""
|
||||||
@ -203,9 +205,9 @@ class FileHelpers:
|
|||||||
) from why
|
) from why
|
||||||
|
|
||||||
# Return hash in specified format.
|
# Return hash in specified format.
|
||||||
if output_format == "hex":
|
if output_as_bytes:
|
||||||
return blake2.hexdigest()
|
|
||||||
return blake2.digest()
|
return blake2.digest()
|
||||||
|
return blake2.hexdigest()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate_file_hash_sha256(file_path: str) -> str:
|
def calculate_file_hash_sha256(file_path: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user