diff --git a/xycrypto/hashes.py b/xycrypto/hashes.py index 81bd37c..0329ec2 100644 --- a/xycrypto/hashes.py +++ b/xycrypto/hashes.py @@ -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() diff --git a/xycrypto/hmac.py b/xycrypto/hmac.py index d6020f2..90e1b34 100644 --- a/xycrypto/hmac.py +++ b/xycrypto/hmac.py @@ -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()