Skip to content

Commit 81d7814

Browse files
author
Daniel Zagaynov
committed
Style fixes
1 parent 2f453bf commit 81d7814

2 files changed

Lines changed: 75 additions & 58 deletions

File tree

src/pyxcrypt/__init__.py

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
"""
22
This 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.
913
See 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.
1217
If not, see <https://www.gnu.org/licenses/>.
1318
"""
1419

@@ -22,18 +27,18 @@
2227

2328
def 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

5965
def 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

8894
def 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

101107
def 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)

src/pyxcrypt/pyxcrypt.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
/*
22
* This 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.
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.
68
*
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.
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.
913
* See 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.
1217
* If not, see <https://www.gnu.org/licenses/>.
1318
*/
1419

@@ -37,7 +42,8 @@ static PyObject * _crypt_gensalt(PyObject *self, PyObject *args)
3742
PyErr_SetString(PyExc_TypeError, "Expected 4 arguments");
3843
return NULL;
3944
}
40-
if (PyArg_ParseTuple(args, "z#kz#i", &prefix, &dumb_sz_1, &count, &rbytes, &dumb_sz_2, &nrbytes) == -1)
45+
if (PyArg_ParseTuple(args, "z#kz#i", &prefix, &dumb_sz_1, &count, &rbytes,
46+
&dumb_sz_2, &nrbytes) == -1)
4147
{
4248
PyErr_SetString(PyExc_TypeError, "Arguments parsing");
4349
return NULL;
@@ -65,7 +71,8 @@ static PyObject * _crypt(PyObject *self, PyObject *args)
6571
PyErr_SetString(PyExc_TypeError, "Expected 2 arguments");
6672
return NULL;
6773
}
68-
if (PyArg_ParseTuple(args, "z#z#", &phrase, &dumb_sz_1, &setting, &dumb_sz_2) == -1)
74+
if (PyArg_ParseTuple(args, "z#z#", &phrase, &dumb_sz_1, &setting,
75+
&dumb_sz_2) == -1)
6976
{
7077
PyErr_SetString(PyExc_TypeError, "Arguments parsing");
7178
return NULL;
@@ -75,7 +82,7 @@ static PyObject * _crypt(PyObject *self, PyObject *args)
7582
PyErr_SetString(PyExc_MemoryError, strerror(errno));
7683
return NULL;
7784
}
78-
memset (data, 0, sizeof(*data));
85+
memset(data, 0, sizeof(*data));
7986
if (crypt_r(phrase, setting, data) == NULL || data->output[0] == '*')
8087
{
8188
PyErr_SetString(PyExc_RuntimeError, strerror(errno));
@@ -110,9 +117,13 @@ static PyObject * _crypt_checksalt(PyObject *self, PyObject *args)
110117
}
111118

112119
static PyMethodDef PyXcryptMethods[] = {
113-
{"_crypt_gensalt", _crypt_gensalt, METH_VARARGS, "compile a string for use as the setting argument to crypt"},
114-
{"_crypt", _crypt, METH_VARARGS, "irreversibly \"hash\" phrase using a cryptographic \"hashing method\""},
115-
{"_crypt_checksalt", _crypt_checksalt, METH_VARARGS, "checks the setting string against the system configuration and reports whether the hashing method and parameters it specifies are acceptable"},
120+
{"_crypt_gensalt", _crypt_gensalt, METH_VARARGS,
121+
"compile a string for use as the setting argument to crypt"},
122+
{"_crypt", _crypt, METH_VARARGS,
123+
"irreversibly \"hash\" phrase using a cryptographic \"hashing method\""},
124+
{"_crypt_checksalt", _crypt_checksalt, METH_VARARGS,
125+
"checks the setting string against the system configuration and reports "
126+
"whether the hashing method and parameters it specifies are acceptable"},
116127
{NULL, NULL, 0, NULL}
117128
};
118129

0 commit comments

Comments
 (0)