Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f5207e61
Commit
f5207e61
authored
Jan 14, 2014
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clinic-ize the crypt module. Derby!
parent
cc1d31e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
15 deletions
+56
-15
Modules/_cryptmodule.c
Modules/_cryptmodule.c
+56
-15
No files found.
Modules/_cryptmodule.c
View file @
f5207e61
...
...
@@ -7,31 +7,72 @@
/* Module crypt */
/*[clinic input]
module crypt
[clinic start generated code]*/
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
static
PyObject
*
crypt_crypt
(
PyObject
*
self
,
PyObject
*
args
)
/*[clinic input]
crypt.crypt
word: 's'
salt: 's'
/
Hash a *word* with the given *salt* and return the hashed password.
*word* will usually be a user's password. *salt* (either a random 2 or 16
character string, possibly prefixed with $digit$ to indicate the method)
will be used to perturb the encryption algorithm and produce distinct
results for a given *word*.
[clinic start generated code]*/
PyDoc_STRVAR
(
crypt_crypt__doc__
,
"crypt(word, salt)
\n
"
"Hash a *word* with the given *salt* and return the hashed password.
\n
"
"
\n
"
"*word* will usually be a user
\'
s password. *salt* (either a random 2 or 16
\n
"
"character string, possibly prefixed with $digit$ to indicate the method)
\n
"
"will be used to perturb the encryption algorithm and produce distinct
\n
"
"results for a given *word*."
);
#define CRYPT_CRYPT_METHODDEF \
{"crypt", (PyCFunction)crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
static
PyObject
*
crypt_crypt_impl
(
PyModuleDef
*
module
,
const
char
*
word
,
const
char
*
salt
);
static
PyObject
*
crypt_crypt
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
char
*
word
,
*
salt
;
PyObject
*
return_value
=
NULL
;
const
char
*
word
;
const
char
*
salt
;
if
(
!
PyArg_ParseTuple
(
args
,
"ss:crypt"
,
&
word
,
&
salt
))
goto
exit
;
return_value
=
crypt_crypt_impl
(
module
,
word
,
salt
);
exit:
return
return_value
;
}
if
(
!
PyArg_ParseTuple
(
args
,
"ss:crypt"
,
&
word
,
&
salt
))
{
return
NULL
;
}
static
PyObject
*
crypt_crypt_impl
(
PyModuleDef
*
module
,
const
char
*
word
,
const
char
*
salt
)
/*[clinic end generated code: checksum=a137540bf6862f9935fc112b8bb1d62d6dd1ad02]*/
{
/* On some platforms (AtheOS) crypt returns NULL for an invalid
salt. Return None in that case. XXX Maybe raise an exception? */
return
Py_BuildValue
(
"s"
,
crypt
(
word
,
salt
));
}
PyDoc_STRVAR
(
crypt_crypt__doc__
,
"crypt(word, salt) -> string
\n
\
word will usually be a user's password. salt is a 2-character string
\n
\
which will be used to select one of 4096 variations of DES. The characters
\n
\
in salt must be either
\"
.
\"
,
\"
/
\"
, or an alphanumeric character. Returns
\n
\
the hashed password as a string, which will be composed of characters from
\n
\
the same alphabet as the salt."
);
static
PyMethodDef
crypt_methods
[]
=
{
{
"crypt"
,
crypt_crypt
,
METH_VARARGS
,
crypt_crypt__doc__
},
CRYPT_CRYPT_METHODDEF
{
NULL
,
NULL
}
/* sentinel */
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment