11"""
22This file is part of pyxcrypt.
33
4- pyxcrypt is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
5- as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6-
7- pyxcrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4+ pyxcrypt is free software: you can redistribute it and/or modify it
5+ under the terms of the GNU General Public License
6+ as published by the Free Software Foundation, either version 3 of
7+ the License, or (at your option) any later version.
8+
9+ pyxcrypt is distributed in the hope that it will be useful,
10+ but WITHOUT ANY WARRANTY;
11+ without even the implied warranty of MERCHANTABILITY or
12+ FITNESS FOR A PARTICULAR PURPOSE.
913See the GNU General Public License for more details.
1014
11- You should have received a copy of the GNU General Public License along with pyxcrypt.
15+ You should have received a copy of the GNU General Public License
16+ along with pyxcrypt.
1217If not, see <https://www.gnu.org/licenses/>.
1318"""
1419
2227
2328def crypt_gensalt (prefix = None , count = 0 , rbytes = None , nrbytes = 0 ):
2429 """
25- Compile a string for use as the setting argument to crypt
26-
27- :param prefix: selects the hashing method to use
28- :type prefix: str, bytes-like object or None
29- :param count: controls the CPU time cost of the hash
30- :type count: int
31- :param rbytes: random bytes for use as a "salt"
32- :type rbytes: str, bytes-like object or None
33- :param nrbytes: length of result
34- :type nrbytes: int
35- :return: salt
36- :rtype: str
30+ Compile a string for use as the setting argument to crypt.
31+
32+ :param prefix: selects the hashing method to use;
33+ :type prefix: str, bytes-like object or None;
34+ :param count: controls the CPU time cost of the hash;
35+ :type count: int;
36+ :param rbytes: random bytes for use as a "salt";
37+ :type rbytes: str, bytes-like object or None;
38+ :param nrbytes: length of result;
39+ :type nrbytes: int;
40+ :return: salt;
41+ :rtype: str.
3742 """
3843 hashes = {"yescrypt" : "$y$" ,
3944 "gost-yescrypt" : "$gy$" ,
@@ -53,21 +58,22 @@ def crypt_gensalt(prefix=None, count=0, rbytes=None, nrbytes=0):
5358 "nt" : "$3$" ,
5459 "bsdicrypt" : "_" ,
5560 "descrypt" : "" }
56- return pyxcrypt ._crypt_gensalt (prefix if prefix not in hashes else hashes [prefix ], count , rbytes , nrbytes )
61+ return pyxcrypt ._crypt_gensalt (prefix if prefix not in hashes else
62+ hashes [prefix ], count , rbytes , nrbytes )
5763
5864
5965def crypt_gensalt_default (count = 0 , rbytes = None , nrbytes = 0 ):
6066 """
61- Same as crypt_gensalt but with the default (prefered) hashing method
62-
63- :param count: controls the CPU time cost of the hash
64- :type count: int
65- :param rbytes: random bytes for use as a "salt"
66- :type rbytes: str, bytes-like object or None
67- :param nrbytes: length of result
68- :type nrbytes: int
69- :return: salt
70- :rtype: str
67+ Same as crypt_gensalt but with the default (prefered) hashing method.
68+
69+ :param count: controls the CPU time cost of the hash;
70+ :type count: int;
71+ :param rbytes: random bytes for use as a "salt";
72+ :type rbytes: str, bytes-like object or None;
73+ :param nrbytes: length of result;
74+ :type nrbytes: int;
75+ :return: salt;
76+ :rtype: str.
7177 """
7278 return crypt_gensalt (None , count , rbytes , nrbytes )
7379
@@ -77,39 +83,39 @@ def crypt_checksalt(salt):
7783 Checks the setting string against the system configuration and reports
7884 whether the hashing method and parameters it specifies are acceptable.
7985
80- :param salt: salt generated by crypt_gensalt
81- :type salt: str, bytes-like object
82- :return: one of CRYPT_SALT_OK/CRYPT_SALT_INVALID/CRYPT_SALT_METHOD_LEGACY
83- :rtype: int
86+ :param salt: salt generated by crypt_gensalt;
87+ :type salt: str, bytes-like object;
88+ :return: one of CRYPT_SALT_OK/CRYPT_SALT_INVALID/CRYPT_SALT_METHOD_LEGACY;
89+ :rtype: int.
8490 """
8591 return pyxcrypt ._crypt_checksalt (salt )
8692
8793
8894def crypt_checksalt_filter (salt ):
8995 """
9096 Same as pyxcrypt.crypt_checksalt but returns True for CRYPT_SALT_OK
91- and False otherwise
97+ and False otherwise.
9298
93- :param salt: salt generated by crypt_gensalt
94- :type salt: str, bytes-like object
95- :return: True for CRYPT_SALT_OK and False otherwise
96- :rtype: bool
99+ :param salt: salt generated by crypt_gensalt;
100+ :type salt: str, bytes-like object;
101+ :return: True for CRYPT_SALT_OK and False otherwise;
102+ :rtype: bool.
97103 """
98104 return pyxcrypt ._crypt_checksalt (salt ) == CRYPT_SALT_OK
99105
100106
101107def crypt (phrase , salt = crypt_gensalt ()):
102108 """
103- Irreversibly “ hash” phrase using a cryptographic “ hashing method” .
109+ Irreversibly " hash" phrase using a cryptographic " hashing method" .
104110 By default parameter "salt" set to crypt_gensalt() without args, which
105111 generates salt with the default "hashing method" with random bytes
106- obtained from the operating system
107-
108- :param phrase: phrase to be "hashed"
109- :type phrase: str, bytes-like object
110- :param salt: salt, generated by crypt_gensalt
111- :type salt: str, bytes-like object
112- :return: "hashed" phrase
113- :rtype: str
112+ obtained from the operating system.
113+
114+ :param phrase: phrase to be "hashed";
115+ :type phrase: str, bytes-like object;
116+ :param salt: salt, generated by crypt_gensalt;
117+ :type salt: str, bytes-like object;
118+ :return: "hashed" phrase;
119+ :rtype: str.
114120 """
115121 return pyxcrypt ._crypt (phrase , salt )
0 commit comments