Skip to content

Commit 0c07131

Browse files
committed
Fix error in get_sigalgs() documentation and address review comments
1 parent 2d47a6c commit 0c07131

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

Doc/library/ssl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ purposes.
218218
Signature algorithms
219219
^^^^^^^^^^^^^^^^^^^^
220220

221-
.. function: get_sigalgs()
221+
.. function:: get_sigalgs()
222222

223223
Return a list of available TLS signature algorithm names used
224224
by servers to complete the TLS handshake or clients requesting

Modules/_ssl.c

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6348,49 +6348,24 @@ _ssl_get_sigalgs_impl(PyObject *module)
63486348
/*[clinic end generated code: output=ab0791b63856854b input=bf74cdad3a19d29e]*/
63496349
{
63506350
#if OPENSSL_VERSION_NUMBER >= 0x30400000L
6351-
const char *sigalgs_list, *sigalg, *end;
6352-
PyObject *item, *result = NULL;
6353-
size_t len;
6354-
6355-
if ((sigalgs_list = SSL_get1_builtin_sigalgs(NULL)) == NULL) {
6356-
PyErr_NoMemory();
6357-
goto error;
6358-
}
6351+
const char *sigalgs;
6352+
PyObject *sigalgs_str, *sigalgs_list;
63596353

6360-
result = PyList_New(0);
6361-
if (result == NULL) {
6354+
if ((sigalgs = SSL_get1_builtin_sigalgs(NULL)) == NULL) {
63626355
PyErr_NoMemory();
6363-
goto error;
6356+
return NULL;
63646357
}
63656358

6366-
sigalg = sigalgs_list;
6367-
while (sigalg) {
6368-
end = strchr(sigalg, ':');
6369-
len = end? end - sigalg : strlen(sigalg);
6370-
6371-
// Alg names are plain ASCII, so there's no chance of a decoding
6372-
// error here. However, an allocation failure could occur when
6373-
// constructing the Unicode version of the names.
6374-
item = PyUnicode_DecodeASCII(sigalg, len, "strict");
6375-
if (item == NULL) {
6376-
goto error;
6377-
}
6378-
6379-
if (PyList_Append(result, item) == -1) {
6380-
Py_DECREF(item);
6381-
goto error;
6382-
}
6383-
6384-
Py_DECREF(item);
6385-
sigalg = end? end + 1 : end;
6359+
if ((sigalgs_str = PyUnicode_DecodeASCII(sigalgs, strlen(sigalgs),
6360+
"strict")) == NULL) {
6361+
OPENSSL_free((void *)sigalgs);
6362+
return NULL;
63866363
}
63876364

6388-
OPENSSL_free((void *)sigalgs_list);
6389-
return result;
6390-
error:
6391-
OPENSSL_free((void *)sigalgs_list);
6392-
Py_XDECREF(result);
6393-
return NULL;
6365+
OPENSSL_free((void *)sigalgs);
6366+
sigalgs_list = PyUnicode_Split(sigalgs_str, _Py_LATIN1_CHR(':'), -1);
6367+
Py_DECREF(sigalgs_str);
6368+
return sigalgs_list;
63946369
#else
63956370
PyErr_SetString(PyExc_NotImplementedError,
63966371
"Getting signature algorithms requires OpenSSL 3.4 or later.");

0 commit comments

Comments
 (0)