Change soft-fail to use the config, rather than env
[rbx.git] / stdlib / ext / openssl / ossl.h
blob3569964886e3d2540f54b202e524c07f44568aec
1 /*
2 * $Id: ossl.h 11708 2007-02-12 23:01:19Z shyouhei $
3 * 'OpenSSL for Ruby' project
4 * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5 * All rights reserved.
6 */
7 /*
8 * This program is licenced under the same licence as Ruby.
9 * (See the file 'LICENCE'.)
11 #if !defined(_OSSL_H_)
12 #define _OSSL_H_
14 #include RUBY_EXTCONF_H
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
21 * OpenSSL has defined RFILE and Ruby has defined RFILE - so undef it!
23 #if defined(RFILE) /*&& !defined(OSSL_DEBUG)*/
24 # undef RFILE
25 #endif
26 #include <ruby.h>
27 #include <rubyio.h>
30 * Check the OpenSSL version
31 * The only supported are:
32 * OpenSSL >= 0.9.7
34 #include <openssl/opensslv.h>
36 #ifdef HAVE_ASSERT_H
37 # include <assert.h>
38 #else
39 # define assert(condition)
40 #endif
42 #if defined(_WIN32)
43 # define OpenFile WINAPI_OpenFile
44 # define OSSL_NO_CONF_API 1
45 #endif
46 #include <errno.h>
47 #include <openssl/err.h>
48 #include <openssl/asn1_mac.h>
49 #include <openssl/x509v3.h>
50 #include <openssl/ssl.h>
51 #include <openssl/pkcs12.h>
52 #include <openssl/pkcs7.h>
53 #include <openssl/hmac.h>
54 #include <openssl/rand.h>
55 #include <openssl/conf.h>
56 #include <openssl/conf_api.h>
57 #undef X509_NAME
58 #undef PKCS7_SIGNER_INFO
59 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
60 # define OSSL_ENGINE_ENABLED
61 # include <openssl/engine.h>
62 #endif
63 #if defined(HAVE_OPENSSL_OCSP_H)
64 # define OSSL_OCSP_ENABLED
65 # include <openssl/ocsp.h>
66 #endif
67 #if defined(_WIN32)
68 # undef OpenFile
69 #endif
72 * Common Module
74 extern VALUE mOSSL;
77 * Common Error Class
79 extern VALUE eOSSLError;
82 * CheckTypes
84 #define OSSL_Check_Kind(obj, klass) do {\
85 if (!rb_obj_is_kind_of(obj, klass)) {\
86 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected kind of %s)",\
87 rb_obj_classname(obj), rb_class2name(klass));\
89 } while (0)
91 #define OSSL_Check_Instance(obj, klass) do {\
92 if (!rb_obj_is_instance_of(obj, klass)) {\
93 ossl_raise(rb_eTypeError, "wrong argument (%s)! (Expected instance of %s)",\
94 rb_obj_classname(obj), rb_class2name(klass));\
96 } while (0)
98 #define OSSL_Check_Same_Class(obj1, obj2) do {\
99 if (!rb_obj_is_instance_of(obj1, rb_obj_class(obj2))) {\
100 ossl_raise(rb_eTypeError, "wrong argument type");\
102 } while (0)
105 * String to HEXString conversion
107 int string2hex(char *, int, char **, int *);
110 * Data Conversion
112 STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
113 STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
114 STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
115 VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
116 VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
117 VALUE ossl_buf2str(char *buf, int len);
118 #define ossl_str_adjust(str, p) \
119 do{\
120 int len = RSTRING(str)->len;\
121 int newlen = (p) - (unsigned char*)RSTRING(str)->ptr;\
122 assert(newlen <= len);\
123 RSTRING(str)->len = newlen;\
124 RSTRING(str)->ptr[newlen] = 0;\
125 }while(0)
128 * our default PEM callback
130 int ossl_pem_passwd_cb(char *, int, int, void *);
133 * ERRor messages
135 #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
136 NORETURN(void ossl_raise(VALUE, const char *, ...));
139 * Verify callback
141 extern int ossl_verify_cb_idx;
143 struct ossl_verify_cb_args {
144 VALUE proc;
145 VALUE preverify_ok;
146 VALUE store_ctx;
149 VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *);
150 int ossl_verify_cb(int, X509_STORE_CTX *);
153 * String to DER String
155 extern ID ossl_s_to_der;
156 VALUE ossl_to_der(VALUE);
157 VALUE ossl_to_der_if_possible(VALUE);
160 * Debug
162 extern VALUE dOSSL;
164 #if defined(HAVE_VA_ARGS_MACRO)
165 #define OSSL_Debug(fmt, ...) do { \
166 if (dOSSL == Qtrue) { \
167 fprintf(stderr, "OSSL_DEBUG: "); \
168 fprintf(stderr, fmt, ##__VA_ARGS__); \
169 fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
171 } while (0)
173 #define OSSL_Warning(fmt, ...) do { \
174 OSSL_Debug(fmt, ##__VA_ARGS__); \
175 rb_warning(fmt, ##__VA_ARGS__); \
176 } while (0)
178 #define OSSL_Warn(fmt, ...) do { \
179 OSSL_Debug(fmt, ##__VA_ARGS__); \
180 rb_warn(fmt, ##__VA_ARGS__); \
181 } while (0)
182 #else
183 void ossl_debug(const char *, ...);
184 #define OSSL_Debug ossl_debug
185 #define OSSL_Warning rb_warning
186 #define OSSL_Warn rb_warn
187 #endif
190 * Include all parts
192 #include "openssl_missing.h"
193 #include "ruby_missing.h"
194 #include "ossl_asn1.h"
195 #include "ossl_bio.h"
196 #include "ossl_bn.h"
197 #include "ossl_cipher.h"
198 #include "ossl_config.h"
199 #include "ossl_digest.h"
200 #include "ossl_hmac.h"
201 #include "ossl_ns_spki.h"
202 #include "ossl_ocsp.h"
203 #include "ossl_pkcs12.h"
204 #include "ossl_pkcs7.h"
205 #include "ossl_pkey.h"
206 #include "ossl_rand.h"
207 #include "ossl_ssl.h"
208 #include "ossl_version.h"
209 #include "ossl_x509.h"
210 #include "ossl_engine.h"
212 void Init_openssl(void);
214 #if defined(__cplusplus)
216 #endif
218 #endif /* _OSSL_H_ */