blob: 56554f02d60d2240a12166d9eac37250642d967d [file] [log] [blame]
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05001/*
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
28extern 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 *
61#define crypto_X509Extension_New_PROTO (char *, int, char *)
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
75extern crypto_X509_New_RETURN crypto_X509_New crypto_X509_New_PROTO;
76extern crypto_X509Name_New_RETURN crypto_X509Name_New crypto_X509Name_New_PROTO;
77extern crypto_X509Req_New_RETURN crypto_X509Req_New crypto_X509Req_New_PROTO;
78extern crypto_X509Store_New_RETURN crypto_X509Store_New crypto_X509Store_New_PROTO;
79extern crypto_PKey_New_RETURN crypto_PKey_New crypto_PKey_New_PROTO;
80extern crypto_X509Extension_New_RETURN crypto_X509Extension_New crypto_X509Extension_New_PROTO;
81extern crypto_PKCS7_New_RETURN crypto_PKCS7_New crypto_PKCS7_New_PROTO;
82extern crypto_NetscapeSPKI_New_RETURN crypto_NetscapeSPKI_New crypto_NetscapeSPKI_New_PROTO;
83
84#else /* crypto_MODULE */
85
86extern 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
Rick Dean5b7b6372009-04-01 11:34:06 -0500120/* Hopefully these don't collide with future official OpenSSL constants, but */
121/* the switch statement of dump_certificate() will alert us if it matters. */
122#ifndef X509_FILETYPE_TEXT
123#define X509_FILETYPE_TEXT (58)
124#endif
125
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500126#endif /* PyOpenSSL_CRYPTO_H_ */