Skip to content

Commit

Permalink
Merge pull request #3 from zyluo/refactor
Browse files Browse the repository at this point in the history
Refactor MerkelTools init
  • Loading branch information
EderSantana authored Sep 26, 2017
2 parents 765aec2 + 98179b9 commit 192f7e9
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions merkletools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,9 @@
class MerkleTools(object):
def __init__(self, hash_type="sha256"):
hash_type = hash_type.lower()
if hash_type == 'sha256':
self.hash_function = hashlib.sha256
elif hash_type == 'md5':
self.hash_function = hashlib.md5
elif hash_type == 'sha224':
self.hash_function = hashlib.sha224
elif hash_type == 'sha384':
self.hash_function = hashlib.sha384
elif hash_type == 'sha512':
self.hash_function = hashlib.sha512
elif hash_type == 'sha3_256':
self.hash_function = hashlib.sha3_256
elif hash_type == 'sha3_224':
self.hash_function = hashlib.sha3_224
elif hash_type == 'sha3_384':
self.hash_function = hashlib.sha3_384
elif hash_type == 'sha3_512':
self.hash_function = hashlib.sha3_512
if hash_type in ['sha256', 'md5', 'sha224', 'sha384', 'sha512',
'sha3_256', 'sha3_224', 'sha3_384', 'sha3_512']:
self.hash_function = getattr(hashlib, hash_type)
else:
raise Exception('`hash_type` {} nor supported'.format(hash_type))

Expand Down

0 comments on commit 192f7e9

Please sign in to comment.