##// END OF EJS Templates
hash-utils: added method to make it return str instead of bytes
super-admin -
r5030:615d827f default
parent child Browse files
Show More
@@ -19,28 +19,38 b''
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import hashlib
22 from rhodecode.lib.str_utils import safe_bytes
22 from rhodecode.lib.str_utils import safe_bytes, safe_str
23 23
24 24
25 25 def md5(s):
26 26 return hashlib.md5(s).hexdigest()
27 27
28 28
29 def md5_safe(s):
30 return md5(safe_bytes(s))
29 def md5_safe(s, return_type=''):
30
31 val = md5(safe_bytes(s))
32 if return_type == 'str':
33 val = safe_str(val)
34 return val
31 35
32 36
33 37 def sha1(s):
34 38 return hashlib.sha1(s).hexdigest()
35 39
36 40
37 def sha1_safe(s):
38 return sha1(safe_bytes(s))
41 def sha1_safe(s, return_type=''):
42 val = sha1(safe_bytes(s))
43 if return_type == 'str':
44 val = safe_str(val)
45 return val
39 46
40 47
41 48 def sha256(s):
42 49 return hashlib.sha256(s).hexdigest()
43 50
44 51
45 def sha256_safe(s):
46 return sha256(safe_bytes(s))
52 def sha256_safe(s, return_type=''):
53 val = sha256(safe_bytes(s))
54 if return_type == 'str':
55 val = safe_str(val)
56 return val
General Comments 0
You need to be logged in to leave comments. Login now