Show More
@@ -1,46 +1,56 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
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 |
|
|
|
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 |
|
|
|
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