Skip to content
Snippets Groups Projects
Commit 4073b824 authored by vlorentz's avatar vlorentz
Browse files

hashutil: Add type annotations to conversion functions

parent 47795c14
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,7 @@ import functools ...@@ -56,7 +56,7 @@ import functools
import hashlib import hashlib
from io import BytesIO from io import BytesIO
import os import os
from typing import Callable, Dict, Optional from typing import Callable, Dict, Optional, Union
ALGORITHMS = set(["sha1", "sha256", "sha1_git", "blake2s256", "blake2b512", "md5"]) ALGORITHMS = set(["sha1", "sha256", "sha1_git", "blake2s256", "blake2b512", "md5"])
"""Hashing algorithms supported by this module""" """Hashing algorithms supported by this module"""
...@@ -293,7 +293,7 @@ def hash_git_data(data, git_type, base_algo="sha1"): ...@@ -293,7 +293,7 @@ def hash_git_data(data, git_type, base_algo="sha1"):
@functools.lru_cache() @functools.lru_cache()
def hash_to_hex(hash): def hash_to_hex(hash: Union[str, bytes]) -> str:
"""Converts a hash (in hex or bytes form) to its hexadecimal ascii form """Converts a hash (in hex or bytes form) to its hexadecimal ascii form
Args: Args:
...@@ -309,7 +309,7 @@ def hash_to_hex(hash): ...@@ -309,7 +309,7 @@ def hash_to_hex(hash):
@functools.lru_cache() @functools.lru_cache()
def hash_to_bytehex(hash): def hash_to_bytehex(hash: bytes) -> bytes:
"""Converts a hash to its hexadecimal bytes representation """Converts a hash to its hexadecimal bytes representation
Args: Args:
...@@ -322,7 +322,7 @@ def hash_to_bytehex(hash): ...@@ -322,7 +322,7 @@ def hash_to_bytehex(hash):
@functools.lru_cache() @functools.lru_cache()
def hash_to_bytes(hash): def hash_to_bytes(hash: Union[str, bytes]) -> bytes:
"""Converts a hash (in hex or bytes form) to its raw bytes form """Converts a hash (in hex or bytes form) to its raw bytes form
Args: Args:
...@@ -338,7 +338,7 @@ def hash_to_bytes(hash): ...@@ -338,7 +338,7 @@ def hash_to_bytes(hash):
@functools.lru_cache() @functools.lru_cache()
def bytehex_to_hash(hex): def bytehex_to_hash(hex: bytes) -> bytes:
"""Converts a hexadecimal bytes representation of a hash to that hash """Converts a hexadecimal bytes representation of a hash to that hash
Args: Args:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment