Show More
@@ -19,28 +19,38 b'' | |||||
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import hashlib |
|
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 | def md5(s): |
|
25 | def md5(s): | |
26 | return hashlib.md5(s).hexdigest() |
|
26 | return hashlib.md5(s).hexdigest() | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | def md5_safe(s): |
|
29 | def md5_safe(s, return_type=''): | |
30 | return md5(safe_bytes(s)) |
|
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 | def sha1(s): |
|
37 | def sha1(s): | |
34 | return hashlib.sha1(s).hexdigest() |
|
38 | return hashlib.sha1(s).hexdigest() | |
35 |
|
39 | |||
36 |
|
40 | |||
37 | def sha1_safe(s): |
|
41 | def sha1_safe(s, return_type=''): | |
38 |
|
|
42 | val = sha1(safe_bytes(s)) | |
|
43 | if return_type == 'str': | |||
|
44 | val = safe_str(val) | |||
|
45 | return val | |||
39 |
|
46 | |||
40 |
|
47 | |||
41 | def sha256(s): |
|
48 | def sha256(s): | |
42 | return hashlib.sha256(s).hexdigest() |
|
49 | return hashlib.sha256(s).hexdigest() | |
43 |
|
50 | |||
44 |
|
51 | |||
45 | def sha256_safe(s): |
|
52 | def sha256_safe(s, return_type=''): | |
46 |
|
|
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