Skip to content

Commit

Permalink
Fix issue with the tests under Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
funilrys committed Dec 13, 2019
1 parent 14db858 commit 70ae4da
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions PyFunceble/helpers/hash.py
Expand Up @@ -61,6 +61,8 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes

from .file import File


class Hash:
"""
Expand All @@ -78,7 +80,7 @@ def __init__(self, algo="sha512_224"):
if not hasattr(hashes, self.algo):
raise ValueError(f"Unknown <algo> ({self.algo})")

def file(self, file_path):
def file(self, file_path, encoding="utf-8"):
"""
Open the given file, and it's content.
Expand All @@ -90,13 +92,13 @@ def file(self, file_path):

digest = hashes.Hash(getattr(hashes, self.algo)(), backend=default_backend())

try:
with open(file_path, "rb") as file_stream:
digest.update(file_stream.read())
content = File(file_path).read(encoding=encoding)

if content:
digest.update(content.encode(encoding))
return digest.finalize().hex()
except FileNotFoundError:
return None

return None

def data(self, data):
"""
Expand Down

0 comments on commit 70ae4da

Please sign in to comment.