Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Improve classmethod hash
Browse files Browse the repository at this point in the history
  • Loading branch information
xymy committed Mar 16, 2020
1 parent 10efac5 commit 0dae526
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion xycrypto/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def copy(self):
def hash(cls, data, **kwargs):
"""Return hash of data from byte string or unicode string."""

ctx = cls(**kwargs)
if isinstance(data, str):
data = data.encode('utf-8')
ctx = cls(**kwargs)
ctx.update(data)
return ctx.finalize()

Expand Down
2 changes: 1 addition & 1 deletion xycrypto/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def copy(self):
def hash(cls, hash_cls, key, data, **kwargs):
"""Return hash of data from byte string or unicode string."""

ctx = cls(hash_cls, key, **kwargs)
if isinstance(data, str):
data = data.encode('utf-8')
ctx = cls(hash_cls, key, **kwargs)
ctx.update(data)
return ctx.finalize()

Expand Down

0 comments on commit 0dae526

Please sign in to comment.