76 static PyObject *
77 crypto_load_privatekey(PyObject *spam, PyObject *args)
78 {
79 crypto_PKeyObj *crypto_PKey_New(EVP_PKEY *, int);
80 int type, len;
81 char *buffer;
82 PyObject *pw = NULL;
83 pem_password_cb *cb = NULL;
84 void *cb_arg = NULL;
85 BIO *bio;
86 EVP_PKEY *pkey;
87
88 if (!PyArg_ParseTuple(args, "is#|O:load_privatekey", &type, &buffer, &len, &pw))
when PyArg_ParseTuple() succeeds
taking False path
89 return NULL;
90
91 if (pw != NULL)
taking True path
92 {
93 if (PyBytes_Check(pw))
when treating unknown struct _typeobject * from OpenSSL/crypto/crypto.c:93 as non-NULL
when considering value == (long int)0 from OpenSSL/crypto/crypto.c:93
taking False path
94 {
95 cb = NULL;
96 cb_arg = PyBytes_AsString(pw);
97 }
98 else if (PyCallable_Check(pw))
when PyCallable_Check() returns 1 (true)
taking True path
99 {
100 cb = global_passphrase_callback;
101 cb_arg = pw;
102 }
103 else
104 {
105 PyErr_SetString(PyExc_TypeError, "Last argument must be string or callable");
106 return NULL;
107 }
108 }
109
110 bio = BIO_new_mem_buf(buffer, len);
111 switch (type)
when following case 1
112 {
113 case X509_FILETYPE_PEM:
114 pkey = PEM_read_bio_PrivateKey(bio, NULL, cb, cb_arg);
115 break;
116
117 case X509_FILETYPE_ASN1:
118 pkey = d2i_PrivateKey_bio(bio, NULL);
119 break;
120
121 default:
122 PyErr_SetString(PyExc_ValueError, "type argument must be FILETYPE_PEM or FILETYPE_ASN1");
123 BIO_free(bio);
124 return NULL;
125 }
126 BIO_free(bio);
127
128 if (pkey == NULL)
when treating unknown struct EVP_PKEY * from OpenSSL/crypto/crypto.c:114 as NULL
taking True path
129 {
130 exception_from_error_queue(crypto_Error);
131 return NULL;
132 }
133
134 return (PyObject *)crypto_PKey_New(pkey, 1);
135 }
returning (PyObject*)NULL without setting an exception
found 3 similar trace(s) to this