@@ -6338,6 +6338,66 @@ _ssl_get_default_verify_paths_impl(PyObject *module)
63386338 return NULL ;
63396339}
63406340
6341+ /*[clinic input]
6342+ @critical_section
6343+ _ssl.get_sigalgs
6344+ [clinic start generated code]*/
6345+
6346+ static PyObject *
6347+ _ssl_get_sigalgs_impl (PyObject * module )
6348+ /*[clinic end generated code: output=ab0791b63856854b input=bf74cdad3a19d29e]*/
6349+ {
6350+ #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+ }
6359+
6360+ result = PyList_New (0 );
6361+ if (result == NULL ) {
6362+ PyErr_NoMemory ();
6363+ goto error ;
6364+ }
6365+
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 ;
6386+ }
6387+
6388+ OPENSSL_free ((void * )sigalgs_list );
6389+ return result ;
6390+ error :
6391+ OPENSSL_free ((void * )sigalgs_list );
6392+ Py_XDECREF (result );
6393+ return NULL ;
6394+ #else
6395+ PyErr_SetString (PyExc_NotImplementedError ,
6396+ "Getting signature algorithms requires OpenSSL 3.4 or later." );
6397+ return NULL ;
6398+ #endif
6399+ }
6400+
63416401static PyObject *
63426402asn1obj2py (_sslmodulestate * state , ASN1_OBJECT * obj )
63436403{
@@ -6741,6 +6801,7 @@ static PyMethodDef PySSL_methods[] = {
67416801 _SSL_RAND_BYTES_METHODDEF
67426802 _SSL_RAND_STATUS_METHODDEF
67436803 _SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF
6804+ _SSL_GET_SIGALGS_METHODDEF
67446805 _SSL_ENUM_CERTIFICATES_METHODDEF
67456806 _SSL_ENUM_CRLS_METHODDEF
67466807 _SSL_TXT2OBJ_METHODDEF
0 commit comments