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