Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * crypto.h |
| 3 | * |
| 4 | * Copyright (C) AB Strakt 2001, All rights reserved |
| 5 | * |
| 6 | * Exports from crypto.c. |
| 7 | * See the file RATIONALE for a short explanation of why this module was written. |
| 8 | * |
| 9 | * Reviewed 2001-07-23 |
| 10 | * |
| 11 | * @(#) $Id: crypto.h,v 1.14 2004/08/09 13:41:25 martin Exp $ |
| 12 | */ |
| 13 | #ifndef PyOpenSSL_CRYPTO_H_ |
| 14 | #define PyOpenSSL_CRYPTO_H_ |
| 15 | |
| 16 | #include <Python.h> |
| 17 | #include "x509.h" |
| 18 | #include "x509name.h" |
| 19 | #include "netscape_spki.h" |
| 20 | #include "x509store.h" |
| 21 | #include "x509req.h" |
| 22 | #include "pkey.h" |
| 23 | #include "x509ext.h" |
| 24 | #include "pkcs7.h" |
| 25 | #include "pkcs12.h" |
| 26 | #include "../util.h" |
| 27 | |
| 28 | extern PyObject *crypto_Error; |
| 29 | |
| 30 | #ifdef exception_from_error_queue |
| 31 | # undef exception_from_error_queue |
| 32 | #endif |
| 33 | #define exception_from_error_queue() do { \ |
| 34 | PyObject *errlist = error_queue_to_list(); \ |
| 35 | PyErr_SetObject(crypto_Error, errlist); \ |
| 36 | Py_DECREF(errlist); \ |
| 37 | } while (0) |
| 38 | |
| 39 | #define crypto_X509_New_NUM 0 |
| 40 | #define crypto_X509_New_RETURN crypto_X509Obj * |
| 41 | #define crypto_X509_New_PROTO (X509 *, int) |
| 42 | |
| 43 | #define crypto_X509Req_New_NUM 1 |
| 44 | #define crypto_X509Req_New_RETURN crypto_X509ReqObj * |
| 45 | #define crypto_X509Req_New_PROTO (X509_REQ *, int) |
| 46 | |
| 47 | #define crypto_X509Store_New_NUM 2 |
| 48 | #define crypto_X509Store_New_RETURN crypto_X509StoreObj * |
| 49 | #define crypto_X509Store_New_PROTO (X509_STORE *, int) |
| 50 | |
| 51 | #define crypto_PKey_New_NUM 3 |
| 52 | #define crypto_PKey_New_RETURN crypto_PKeyObj * |
| 53 | #define crypto_PKey_New_PROTO (EVP_PKEY *, int) |
| 54 | |
| 55 | #define crypto_X509Name_New_NUM 4 |
| 56 | #define crypto_X509Name_New_RETURN crypto_X509NameObj * |
| 57 | #define crypto_X509Name_New_PROTO (X509_NAME *, int) |
| 58 | |
| 59 | #define crypto_X509Extension_New_NUM 5 |
| 60 | #define crypto_X509Extension_New_RETURN crypto_X509ExtensionObj * |
Rick Dean | 47262da | 2009-07-08 16:17:17 -0500 | [diff] [blame^] | 61 | #define crypto_X509Extension_New_PROTO (char *, int, char *, crypto_X509Obj *, crypto_X509Obj *) |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 62 | |
| 63 | #define crypto_PKCS7_New_NUM 6 |
| 64 | #define crypto_PKCS7_New_RETURN crypto_PKCS7Obj * |
| 65 | #define crypto_PKCS7_New_PROTO (PKCS7 *, int) |
| 66 | |
| 67 | #define crypto_NetscapeSPKI_New_NUM 7 |
| 68 | #define crypto_NetscapeSPKI_New_RETURN crypto_NetscapeSPKIObj * |
| 69 | #define crypto_NetscapeSPKI_New_PROTO (NETSCAPE_SPKI *, int) |
| 70 | |
| 71 | #define crypto_API_pointers 8 |
| 72 | |
| 73 | #ifdef crypto_MODULE |
| 74 | |
| 75 | extern crypto_X509_New_RETURN crypto_X509_New crypto_X509_New_PROTO; |
| 76 | extern crypto_X509Name_New_RETURN crypto_X509Name_New crypto_X509Name_New_PROTO; |
| 77 | extern crypto_X509Req_New_RETURN crypto_X509Req_New crypto_X509Req_New_PROTO; |
| 78 | extern crypto_X509Store_New_RETURN crypto_X509Store_New crypto_X509Store_New_PROTO; |
| 79 | extern crypto_PKey_New_RETURN crypto_PKey_New crypto_PKey_New_PROTO; |
| 80 | extern crypto_X509Extension_New_RETURN crypto_X509Extension_New crypto_X509Extension_New_PROTO; |
| 81 | extern crypto_PKCS7_New_RETURN crypto_PKCS7_New crypto_PKCS7_New_PROTO; |
| 82 | extern crypto_NetscapeSPKI_New_RETURN crypto_NetscapeSPKI_New crypto_NetscapeSPKI_New_PROTO; |
| 83 | |
| 84 | #else /* crypto_MODULE */ |
| 85 | |
| 86 | extern void **crypto_API; |
| 87 | |
| 88 | #define crypto_X509_New \ |
| 89 | (*(crypto_X509_New_RETURN (*)crypto_X509_New_PROTO) crypto_API[crypto_X509_New_NUM]) |
| 90 | #define crypto_X509Name_New \ |
| 91 | (*(crypto_X509Name_New_RETURN (*)crypto_X509Name_New_PROTO) crypto_API[crypto_X509Name_New_NUM]) |
| 92 | #define crypto_X509Req_New \ |
| 93 | (*(crypto_X509Req_New_RETURN (*)crypto_X509Req_New_PROTO) crypto_API[crypto_X509Req_New_NUM]) |
| 94 | #define crypto_X509Store_New \ |
| 95 | (*(crypto_X509Store_New_RETURN (*)crypto_X509Store_New_PROTO) crypto_API[crypto_X509Store_New_NUM]) |
| 96 | #define crypto_PKey_New \ |
| 97 | (*(crypto_PKey_New_RETURN (*)crypto_PKey_New_PROTO) crypto_API[crypto_PKey_New_NUM]) |
| 98 | #define crypto_X509Extension_New\ |
| 99 | (*(crypto_X509Extension_New_RETURN (*)crypto_X509Extension_New_PROTO) crypto_API[crypto_X509Extension_New_NUM]) |
| 100 | #define crypto_PKCS7_New \ |
| 101 | (*(crypto_PKCS7_New_RETURN (*)crypto_PKCS7_New_PROTO) crypto_API[crypto_PKCS7_New_NUM]) |
| 102 | #define crypto_NetscapeSPKI_New \ |
| 103 | (*(crypto_NetscapeSPKI_New_RETURN (*)crypto_NetscapeSPKI_New_PROTO) crypto_API[crypto_NetscapeSPKI_New_NUM]) |
| 104 | |
| 105 | #define import_crypto() \ |
| 106 | { \ |
| 107 | PyObject *crypto_module = PyImport_ImportModule("OpenSSL.crypto"); \ |
| 108 | if (crypto_module != NULL) { \ |
| 109 | PyObject *crypto_dict, *crypto_api_object; \ |
| 110 | crypto_dict = PyModule_GetDict(crypto_module); \ |
| 111 | crypto_api_object = PyDict_GetItemString(crypto_dict, "_C_API"); \ |
| 112 | if (PyCObject_Check(crypto_api_object)) { \ |
| 113 | crypto_API = (void **)PyCObject_AsVoidPtr(crypto_api_object); \ |
| 114 | } \ |
| 115 | } \ |
| 116 | } |
| 117 | |
| 118 | #endif /* crypto_MODULE */ |
| 119 | |
Jean-Paul Calderone | 2685e43 | 2009-04-01 12:58:26 -0400 | [diff] [blame] | 120 | /* Define a new type for emitting text. Hopefully these don't collide with |
| 121 | * future official OpenSSL constants, but the switch statement of |
| 122 | * dump_certificate() will alert us if it matters. |
| 123 | */ |
Rick Dean | 5b7b637 | 2009-04-01 11:34:06 -0500 | [diff] [blame] | 124 | #ifndef X509_FILETYPE_TEXT |
| 125 | #define X509_FILETYPE_TEXT (58) |
| 126 | #endif |
| 127 | |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 128 | #endif /* PyOpenSSL_CRYPTO_H_ */ |