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