zig_example 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/mkmf.rb +5 -2
- data/lib/zig_example/version.rb +1 -1
- metadata +3 -56
- data/ext/openssl/openssl_missing.c +0 -40
- data/ext/openssl/openssl_missing.h +0 -238
- data/ext/openssl/ossl.c +0 -1295
- data/ext/openssl/ossl.h +0 -201
- data/ext/openssl/ossl_asn1.c +0 -1891
- data/ext/openssl/ossl_asn1.h +0 -62
- data/ext/openssl/ossl_bio.c +0 -42
- data/ext/openssl/ossl_bio.h +0 -16
- data/ext/openssl/ossl_bn.c +0 -1344
- data/ext/openssl/ossl_bn.h +0 -26
- data/ext/openssl/ossl_cipher.c +0 -1074
- data/ext/openssl/ossl_cipher.h +0 -20
- data/ext/openssl/ossl_config.c +0 -460
- data/ext/openssl/ossl_config.h +0 -16
- data/ext/openssl/ossl_digest.c +0 -425
- data/ext/openssl/ossl_digest.h +0 -20
- data/ext/openssl/ossl_engine.c +0 -568
- data/ext/openssl/ossl_engine.h +0 -19
- data/ext/openssl/ossl_hmac.c +0 -310
- data/ext/openssl/ossl_hmac.h +0 -18
- data/ext/openssl/ossl_kdf.c +0 -311
- data/ext/openssl/ossl_kdf.h +0 -6
- data/ext/openssl/ossl_ns_spki.c +0 -405
- data/ext/openssl/ossl_ns_spki.h +0 -19
- data/ext/openssl/ossl_ocsp.c +0 -1965
- data/ext/openssl/ossl_ocsp.h +0 -23
- data/ext/openssl/ossl_pkcs12.c +0 -275
- data/ext/openssl/ossl_pkcs12.h +0 -13
- data/ext/openssl/ossl_pkcs7.c +0 -1081
- data/ext/openssl/ossl_pkcs7.h +0 -36
- data/ext/openssl/ossl_pkey.c +0 -1624
- data/ext/openssl/ossl_pkey.h +0 -204
- data/ext/openssl/ossl_pkey_dh.c +0 -440
- data/ext/openssl/ossl_pkey_dsa.c +0 -359
- data/ext/openssl/ossl_pkey_ec.c +0 -1655
- data/ext/openssl/ossl_pkey_rsa.c +0 -579
- data/ext/openssl/ossl_rand.c +0 -200
- data/ext/openssl/ossl_rand.h +0 -18
- data/ext/openssl/ossl_ssl.c +0 -3142
- data/ext/openssl/ossl_ssl.h +0 -36
- data/ext/openssl/ossl_ssl_session.c +0 -331
- data/ext/openssl/ossl_ts.c +0 -1539
- data/ext/openssl/ossl_ts.h +0 -16
- data/ext/openssl/ossl_x509.c +0 -256
- data/ext/openssl/ossl_x509.h +0 -115
- data/ext/openssl/ossl_x509attr.c +0 -324
- data/ext/openssl/ossl_x509cert.c +0 -1002
- data/ext/openssl/ossl_x509crl.c +0 -545
- data/ext/openssl/ossl_x509ext.c +0 -490
- data/ext/openssl/ossl_x509name.c +0 -597
- data/ext/openssl/ossl_x509req.c +0 -444
- data/ext/openssl/ossl_x509revoked.c +0 -300
- data/ext/openssl/ossl_x509store.c +0 -986
data/ext/openssl/ossl_engine.c
DELETED
@@ -1,568 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* 'OpenSSL for Ruby' project
|
3
|
-
* Copyright (C) 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
4
|
-
* All rights reserved.
|
5
|
-
*/
|
6
|
-
/*
|
7
|
-
* This program is licensed under the same licence as Ruby.
|
8
|
-
* (See the file 'LICENCE'.)
|
9
|
-
*/
|
10
|
-
#include "ossl.h"
|
11
|
-
|
12
|
-
#ifdef OSSL_USE_ENGINE
|
13
|
-
# include <openssl/engine.h>
|
14
|
-
|
15
|
-
#define NewEngine(klass) \
|
16
|
-
TypedData_Wrap_Struct((klass), &ossl_engine_type, 0)
|
17
|
-
#define SetEngine(obj, engine) do { \
|
18
|
-
if (!(engine)) { \
|
19
|
-
ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
|
20
|
-
} \
|
21
|
-
RTYPEDDATA_DATA(obj) = (engine); \
|
22
|
-
} while(0)
|
23
|
-
#define GetEngine(obj, engine) do { \
|
24
|
-
TypedData_Get_Struct((obj), ENGINE, &ossl_engine_type, (engine)); \
|
25
|
-
if (!(engine)) { \
|
26
|
-
ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
|
27
|
-
} \
|
28
|
-
} while (0)
|
29
|
-
|
30
|
-
/*
|
31
|
-
* Classes
|
32
|
-
*/
|
33
|
-
/* Document-class: OpenSSL::Engine
|
34
|
-
*
|
35
|
-
* This class is the access to openssl's ENGINE cryptographic module
|
36
|
-
* implementation.
|
37
|
-
*
|
38
|
-
* See also, https://www.openssl.org/docs/crypto/engine.html
|
39
|
-
*/
|
40
|
-
VALUE cEngine;
|
41
|
-
/* Document-class: OpenSSL::Engine::EngineError
|
42
|
-
*
|
43
|
-
* This is the generic exception for OpenSSL::Engine related errors
|
44
|
-
*/
|
45
|
-
VALUE eEngineError;
|
46
|
-
|
47
|
-
/*
|
48
|
-
* Private
|
49
|
-
*/
|
50
|
-
#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000
|
51
|
-
#define OSSL_ENGINE_LOAD_IF_MATCH(engine_name, x) \
|
52
|
-
do{\
|
53
|
-
if(!strcmp(#engine_name, RSTRING_PTR(name))){\
|
54
|
-
if (OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_##x, NULL))\
|
55
|
-
return Qtrue;\
|
56
|
-
else\
|
57
|
-
ossl_raise(eEngineError, "OPENSSL_init_crypto"); \
|
58
|
-
}\
|
59
|
-
}while(0)
|
60
|
-
#else
|
61
|
-
#define OSSL_ENGINE_LOAD_IF_MATCH(engine_name, x) \
|
62
|
-
do{\
|
63
|
-
if(!strcmp(#engine_name, RSTRING_PTR(name))){\
|
64
|
-
ENGINE_load_##engine_name();\
|
65
|
-
return Qtrue;\
|
66
|
-
}\
|
67
|
-
}while(0)
|
68
|
-
#endif
|
69
|
-
|
70
|
-
static void
|
71
|
-
ossl_engine_free(void *engine)
|
72
|
-
{
|
73
|
-
ENGINE_free(engine);
|
74
|
-
}
|
75
|
-
|
76
|
-
static const rb_data_type_t ossl_engine_type = {
|
77
|
-
"OpenSSL/Engine",
|
78
|
-
{
|
79
|
-
0, ossl_engine_free,
|
80
|
-
},
|
81
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
82
|
-
};
|
83
|
-
|
84
|
-
/*
|
85
|
-
* call-seq:
|
86
|
-
* OpenSSL::Engine.load(name = nil)
|
87
|
-
*
|
88
|
-
* This method loads engines. If _name_ is nil, then all builtin engines are
|
89
|
-
* loaded. Otherwise, the given _name_, as a String, is loaded if available to
|
90
|
-
* your runtime, and returns true. If _name_ is not found, then nil is
|
91
|
-
* returned.
|
92
|
-
*
|
93
|
-
*/
|
94
|
-
static VALUE
|
95
|
-
ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
|
96
|
-
{
|
97
|
-
VALUE name;
|
98
|
-
|
99
|
-
rb_scan_args(argc, argv, "01", &name);
|
100
|
-
if(NIL_P(name)){
|
101
|
-
ENGINE_load_builtin_engines();
|
102
|
-
return Qtrue;
|
103
|
-
}
|
104
|
-
StringValueCStr(name);
|
105
|
-
#ifdef HAVE_ENGINE_LOAD_DYNAMIC
|
106
|
-
OSSL_ENGINE_LOAD_IF_MATCH(dynamic, DYNAMIC);
|
107
|
-
#endif
|
108
|
-
#ifndef OPENSSL_NO_STATIC_ENGINE
|
109
|
-
#ifdef HAVE_ENGINE_LOAD_4758CCA
|
110
|
-
OSSL_ENGINE_LOAD_IF_MATCH(4758cca, 4758CCA);
|
111
|
-
#endif
|
112
|
-
#ifdef HAVE_ENGINE_LOAD_AEP
|
113
|
-
OSSL_ENGINE_LOAD_IF_MATCH(aep, AEP);
|
114
|
-
#endif
|
115
|
-
#ifdef HAVE_ENGINE_LOAD_ATALLA
|
116
|
-
OSSL_ENGINE_LOAD_IF_MATCH(atalla, ATALLA);
|
117
|
-
#endif
|
118
|
-
#ifdef HAVE_ENGINE_LOAD_CHIL
|
119
|
-
OSSL_ENGINE_LOAD_IF_MATCH(chil, CHIL);
|
120
|
-
#endif
|
121
|
-
#ifdef HAVE_ENGINE_LOAD_CSWIFT
|
122
|
-
OSSL_ENGINE_LOAD_IF_MATCH(cswift, CSWIFT);
|
123
|
-
#endif
|
124
|
-
#ifdef HAVE_ENGINE_LOAD_NURON
|
125
|
-
OSSL_ENGINE_LOAD_IF_MATCH(nuron, NURON);
|
126
|
-
#endif
|
127
|
-
#ifdef HAVE_ENGINE_LOAD_SUREWARE
|
128
|
-
OSSL_ENGINE_LOAD_IF_MATCH(sureware, SUREWARE);
|
129
|
-
#endif
|
130
|
-
#ifdef HAVE_ENGINE_LOAD_UBSEC
|
131
|
-
OSSL_ENGINE_LOAD_IF_MATCH(ubsec, UBSEC);
|
132
|
-
#endif
|
133
|
-
#ifdef HAVE_ENGINE_LOAD_PADLOCK
|
134
|
-
OSSL_ENGINE_LOAD_IF_MATCH(padlock, PADLOCK);
|
135
|
-
#endif
|
136
|
-
#ifdef HAVE_ENGINE_LOAD_CAPI
|
137
|
-
OSSL_ENGINE_LOAD_IF_MATCH(capi, CAPI);
|
138
|
-
#endif
|
139
|
-
#ifdef HAVE_ENGINE_LOAD_GMP
|
140
|
-
OSSL_ENGINE_LOAD_IF_MATCH(gmp, GMP);
|
141
|
-
#endif
|
142
|
-
#ifdef HAVE_ENGINE_LOAD_GOST
|
143
|
-
OSSL_ENGINE_LOAD_IF_MATCH(gost, GOST);
|
144
|
-
#endif
|
145
|
-
#endif
|
146
|
-
#ifdef HAVE_ENGINE_LOAD_CRYPTODEV
|
147
|
-
OSSL_ENGINE_LOAD_IF_MATCH(cryptodev, CRYPTODEV);
|
148
|
-
#endif
|
149
|
-
OSSL_ENGINE_LOAD_IF_MATCH(openssl, OPENSSL);
|
150
|
-
rb_warning("no such builtin loader for `%"PRIsVALUE"'", name);
|
151
|
-
return Qnil;
|
152
|
-
}
|
153
|
-
|
154
|
-
/*
|
155
|
-
* call-seq:
|
156
|
-
* OpenSSL::Engine.cleanup
|
157
|
-
*
|
158
|
-
* It is only necessary to run cleanup when engines are loaded via
|
159
|
-
* OpenSSL::Engine.load. However, running cleanup before exit is recommended.
|
160
|
-
*
|
161
|
-
* Note that this is needed and works only in OpenSSL < 1.1.0.
|
162
|
-
*/
|
163
|
-
static VALUE
|
164
|
-
ossl_engine_s_cleanup(VALUE self)
|
165
|
-
{
|
166
|
-
#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000
|
167
|
-
ENGINE_cleanup();
|
168
|
-
#endif
|
169
|
-
return Qnil;
|
170
|
-
}
|
171
|
-
|
172
|
-
/*
|
173
|
-
* call-seq:
|
174
|
-
* OpenSSL::Engine.engines -> [engine, ...]
|
175
|
-
*
|
176
|
-
* Returns an array of currently loaded engines.
|
177
|
-
*/
|
178
|
-
static VALUE
|
179
|
-
ossl_engine_s_engines(VALUE klass)
|
180
|
-
{
|
181
|
-
ENGINE *e;
|
182
|
-
VALUE ary, obj;
|
183
|
-
|
184
|
-
ary = rb_ary_new();
|
185
|
-
for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
|
186
|
-
obj = NewEngine(klass);
|
187
|
-
/* Need a ref count of two here because of ENGINE_free being
|
188
|
-
* called internally by OpenSSL when moving to the next ENGINE
|
189
|
-
* and by us when releasing the ENGINE reference */
|
190
|
-
ENGINE_up_ref(e);
|
191
|
-
SetEngine(obj, e);
|
192
|
-
rb_ary_push(ary, obj);
|
193
|
-
}
|
194
|
-
|
195
|
-
return ary;
|
196
|
-
}
|
197
|
-
|
198
|
-
/*
|
199
|
-
* call-seq:
|
200
|
-
* OpenSSL::Engine.by_id(name) -> engine
|
201
|
-
*
|
202
|
-
* Fetches the engine as specified by the _id_ String.
|
203
|
-
*
|
204
|
-
* OpenSSL::Engine.by_id("openssl")
|
205
|
-
* => #<OpenSSL::Engine id="openssl" name="Software engine support">
|
206
|
-
*
|
207
|
-
* See OpenSSL::Engine.engines for the currently loaded engines.
|
208
|
-
*/
|
209
|
-
static VALUE
|
210
|
-
ossl_engine_s_by_id(VALUE klass, VALUE id)
|
211
|
-
{
|
212
|
-
ENGINE *e;
|
213
|
-
VALUE obj;
|
214
|
-
|
215
|
-
StringValueCStr(id);
|
216
|
-
ossl_engine_s_load(1, &id, klass);
|
217
|
-
obj = NewEngine(klass);
|
218
|
-
if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
|
219
|
-
ossl_raise(eEngineError, NULL);
|
220
|
-
SetEngine(obj, e);
|
221
|
-
if(rb_block_given_p()) rb_yield(obj);
|
222
|
-
if(!ENGINE_init(e))
|
223
|
-
ossl_raise(eEngineError, NULL);
|
224
|
-
ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
|
225
|
-
0, NULL, (void(*)(void))ossl_pem_passwd_cb);
|
226
|
-
ossl_clear_error();
|
227
|
-
|
228
|
-
return obj;
|
229
|
-
}
|
230
|
-
|
231
|
-
/*
|
232
|
-
* call-seq:
|
233
|
-
* engine.id -> string
|
234
|
-
*
|
235
|
-
* Gets the id for this engine.
|
236
|
-
*
|
237
|
-
* OpenSSL::Engine.load
|
238
|
-
* OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...]
|
239
|
-
* OpenSSL::Engine.engines.first.id
|
240
|
-
* #=> "rsax"
|
241
|
-
*/
|
242
|
-
static VALUE
|
243
|
-
ossl_engine_get_id(VALUE self)
|
244
|
-
{
|
245
|
-
ENGINE *e;
|
246
|
-
GetEngine(self, e);
|
247
|
-
return rb_str_new2(ENGINE_get_id(e));
|
248
|
-
}
|
249
|
-
|
250
|
-
/*
|
251
|
-
* call-seq:
|
252
|
-
* engine.name -> string
|
253
|
-
*
|
254
|
-
* Get the descriptive name for this engine.
|
255
|
-
*
|
256
|
-
* OpenSSL::Engine.load
|
257
|
-
* OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...]
|
258
|
-
* OpenSSL::Engine.engines.first.name
|
259
|
-
* #=> "RSAX engine support"
|
260
|
-
*
|
261
|
-
*/
|
262
|
-
static VALUE
|
263
|
-
ossl_engine_get_name(VALUE self)
|
264
|
-
{
|
265
|
-
ENGINE *e;
|
266
|
-
GetEngine(self, e);
|
267
|
-
return rb_str_new2(ENGINE_get_name(e));
|
268
|
-
}
|
269
|
-
|
270
|
-
/*
|
271
|
-
* call-seq:
|
272
|
-
* engine.finish -> nil
|
273
|
-
*
|
274
|
-
* Releases all internal structural references for this engine.
|
275
|
-
*
|
276
|
-
* May raise an EngineError if the engine is unavailable
|
277
|
-
*/
|
278
|
-
static VALUE
|
279
|
-
ossl_engine_finish(VALUE self)
|
280
|
-
{
|
281
|
-
ENGINE *e;
|
282
|
-
|
283
|
-
GetEngine(self, e);
|
284
|
-
if(!ENGINE_finish(e)) ossl_raise(eEngineError, NULL);
|
285
|
-
|
286
|
-
return Qnil;
|
287
|
-
}
|
288
|
-
|
289
|
-
/*
|
290
|
-
* call-seq:
|
291
|
-
* engine.cipher(name) -> OpenSSL::Cipher
|
292
|
-
*
|
293
|
-
* Returns a new instance of OpenSSL::Cipher by _name_, if it is available in
|
294
|
-
* this engine.
|
295
|
-
*
|
296
|
-
* An EngineError will be raised if the cipher is unavailable.
|
297
|
-
*
|
298
|
-
* e = OpenSSL::Engine.by_id("openssl")
|
299
|
-
* => #<OpenSSL::Engine id="openssl" name="Software engine support">
|
300
|
-
* e.cipher("RC4")
|
301
|
-
* => #<OpenSSL::Cipher:0x007fc5cacc3048>
|
302
|
-
*
|
303
|
-
*/
|
304
|
-
static VALUE
|
305
|
-
ossl_engine_get_cipher(VALUE self, VALUE name)
|
306
|
-
{
|
307
|
-
ENGINE *e;
|
308
|
-
const EVP_CIPHER *ciph, *tmp;
|
309
|
-
int nid;
|
310
|
-
|
311
|
-
tmp = EVP_get_cipherbyname(StringValueCStr(name));
|
312
|
-
if(!tmp) ossl_raise(eEngineError, "no such cipher `%"PRIsVALUE"'", name);
|
313
|
-
nid = EVP_CIPHER_nid(tmp);
|
314
|
-
GetEngine(self, e);
|
315
|
-
ciph = ENGINE_get_cipher(e, nid);
|
316
|
-
if(!ciph) ossl_raise(eEngineError, NULL);
|
317
|
-
|
318
|
-
return ossl_cipher_new(ciph);
|
319
|
-
}
|
320
|
-
|
321
|
-
/*
|
322
|
-
* call-seq:
|
323
|
-
* engine.digest(name) -> OpenSSL::Digest
|
324
|
-
*
|
325
|
-
* Returns a new instance of OpenSSL::Digest by _name_.
|
326
|
-
*
|
327
|
-
* Will raise an EngineError if the digest is unavailable.
|
328
|
-
*
|
329
|
-
* e = OpenSSL::Engine.by_id("openssl")
|
330
|
-
* #=> #<OpenSSL::Engine id="openssl" name="Software engine support">
|
331
|
-
* e.digest("SHA1")
|
332
|
-
* #=> #<OpenSSL::Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709>
|
333
|
-
* e.digest("zomg")
|
334
|
-
* #=> OpenSSL::Engine::EngineError: no such digest `zomg'
|
335
|
-
*/
|
336
|
-
static VALUE
|
337
|
-
ossl_engine_get_digest(VALUE self, VALUE name)
|
338
|
-
{
|
339
|
-
ENGINE *e;
|
340
|
-
const EVP_MD *md, *tmp;
|
341
|
-
int nid;
|
342
|
-
|
343
|
-
tmp = EVP_get_digestbyname(StringValueCStr(name));
|
344
|
-
if(!tmp) ossl_raise(eEngineError, "no such digest `%"PRIsVALUE"'", name);
|
345
|
-
nid = EVP_MD_nid(tmp);
|
346
|
-
GetEngine(self, e);
|
347
|
-
md = ENGINE_get_digest(e, nid);
|
348
|
-
if(!md) ossl_raise(eEngineError, NULL);
|
349
|
-
|
350
|
-
return ossl_digest_new(md);
|
351
|
-
}
|
352
|
-
|
353
|
-
/*
|
354
|
-
* call-seq:
|
355
|
-
* engine.load_private_key(id = nil, data = nil) -> OpenSSL::PKey
|
356
|
-
*
|
357
|
-
* Loads the given private key identified by _id_ and _data_.
|
358
|
-
*
|
359
|
-
* An EngineError is raised of the OpenSSL::PKey is unavailable.
|
360
|
-
*
|
361
|
-
*/
|
362
|
-
static VALUE
|
363
|
-
ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
|
364
|
-
{
|
365
|
-
ENGINE *e;
|
366
|
-
EVP_PKEY *pkey;
|
367
|
-
VALUE id, data, obj;
|
368
|
-
char *sid, *sdata;
|
369
|
-
|
370
|
-
rb_scan_args(argc, argv, "02", &id, &data);
|
371
|
-
sid = NIL_P(id) ? NULL : StringValueCStr(id);
|
372
|
-
sdata = NIL_P(data) ? NULL : StringValueCStr(data);
|
373
|
-
GetEngine(self, e);
|
374
|
-
pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
|
375
|
-
if (!pkey) ossl_raise(eEngineError, NULL);
|
376
|
-
obj = ossl_pkey_new(pkey);
|
377
|
-
OSSL_PKEY_SET_PRIVATE(obj);
|
378
|
-
|
379
|
-
return obj;
|
380
|
-
}
|
381
|
-
|
382
|
-
/*
|
383
|
-
* call-seq:
|
384
|
-
* engine.load_public_key(id = nil, data = nil) -> OpenSSL::PKey
|
385
|
-
*
|
386
|
-
* Loads the given public key identified by _id_ and _data_.
|
387
|
-
*
|
388
|
-
* An EngineError is raised of the OpenSSL::PKey is unavailable.
|
389
|
-
*
|
390
|
-
*/
|
391
|
-
static VALUE
|
392
|
-
ossl_engine_load_pubkey(int argc, VALUE *argv, VALUE self)
|
393
|
-
{
|
394
|
-
ENGINE *e;
|
395
|
-
EVP_PKEY *pkey;
|
396
|
-
VALUE id, data;
|
397
|
-
char *sid, *sdata;
|
398
|
-
|
399
|
-
rb_scan_args(argc, argv, "02", &id, &data);
|
400
|
-
sid = NIL_P(id) ? NULL : StringValueCStr(id);
|
401
|
-
sdata = NIL_P(data) ? NULL : StringValueCStr(data);
|
402
|
-
GetEngine(self, e);
|
403
|
-
pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
|
404
|
-
if (!pkey) ossl_raise(eEngineError, NULL);
|
405
|
-
|
406
|
-
return ossl_pkey_new(pkey);
|
407
|
-
}
|
408
|
-
|
409
|
-
/*
|
410
|
-
* call-seq:
|
411
|
-
* engine.set_default(flag)
|
412
|
-
*
|
413
|
-
* Set the defaults for this engine with the given _flag_.
|
414
|
-
*
|
415
|
-
* These flags are used to control combinations of algorithm methods.
|
416
|
-
*
|
417
|
-
* _flag_ can be one of the following, other flags are available depending on
|
418
|
-
* your OS.
|
419
|
-
*
|
420
|
-
* [All flags] 0xFFFF
|
421
|
-
* [No flags] 0x0000
|
422
|
-
*
|
423
|
-
* See also <openssl/engine.h>
|
424
|
-
*/
|
425
|
-
static VALUE
|
426
|
-
ossl_engine_set_default(VALUE self, VALUE flag)
|
427
|
-
{
|
428
|
-
ENGINE *e;
|
429
|
-
int f = NUM2INT(flag);
|
430
|
-
|
431
|
-
GetEngine(self, e);
|
432
|
-
ENGINE_set_default(e, f);
|
433
|
-
|
434
|
-
return Qtrue;
|
435
|
-
}
|
436
|
-
|
437
|
-
/*
|
438
|
-
* call-seq:
|
439
|
-
* engine.ctrl_cmd(command, value = nil) -> engine
|
440
|
-
*
|
441
|
-
* Sends the given _command_ to this engine.
|
442
|
-
*
|
443
|
-
* Raises an EngineError if the command fails.
|
444
|
-
*/
|
445
|
-
static VALUE
|
446
|
-
ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
|
447
|
-
{
|
448
|
-
ENGINE *e;
|
449
|
-
VALUE cmd, val;
|
450
|
-
int ret;
|
451
|
-
|
452
|
-
GetEngine(self, e);
|
453
|
-
rb_scan_args(argc, argv, "11", &cmd, &val);
|
454
|
-
ret = ENGINE_ctrl_cmd_string(e, StringValueCStr(cmd),
|
455
|
-
NIL_P(val) ? NULL : StringValueCStr(val), 0);
|
456
|
-
if (!ret) ossl_raise(eEngineError, NULL);
|
457
|
-
|
458
|
-
return self;
|
459
|
-
}
|
460
|
-
|
461
|
-
static VALUE
|
462
|
-
ossl_engine_cmd_flag_to_name(int flag)
|
463
|
-
{
|
464
|
-
switch(flag){
|
465
|
-
case ENGINE_CMD_FLAG_NUMERIC: return rb_str_new2("NUMERIC");
|
466
|
-
case ENGINE_CMD_FLAG_STRING: return rb_str_new2("STRING");
|
467
|
-
case ENGINE_CMD_FLAG_NO_INPUT: return rb_str_new2("NO_INPUT");
|
468
|
-
case ENGINE_CMD_FLAG_INTERNAL: return rb_str_new2("INTERNAL");
|
469
|
-
default: return rb_str_new2("UNKNOWN");
|
470
|
-
}
|
471
|
-
}
|
472
|
-
|
473
|
-
/*
|
474
|
-
* call-seq:
|
475
|
-
* engine.cmds -> [["name", "description", "flags"], ...]
|
476
|
-
*
|
477
|
-
* Returns an array of command definitions for the current engine
|
478
|
-
*/
|
479
|
-
static VALUE
|
480
|
-
ossl_engine_get_cmds(VALUE self)
|
481
|
-
{
|
482
|
-
ENGINE *e;
|
483
|
-
const ENGINE_CMD_DEFN *defn, *p;
|
484
|
-
VALUE ary, tmp;
|
485
|
-
|
486
|
-
GetEngine(self, e);
|
487
|
-
ary = rb_ary_new();
|
488
|
-
if ((defn = ENGINE_get_cmd_defns(e)) != NULL){
|
489
|
-
for (p = defn; p->cmd_num > 0; p++){
|
490
|
-
tmp = rb_ary_new();
|
491
|
-
rb_ary_push(tmp, rb_str_new2(p->cmd_name));
|
492
|
-
rb_ary_push(tmp, rb_str_new2(p->cmd_desc));
|
493
|
-
rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(p->cmd_flags));
|
494
|
-
rb_ary_push(ary, tmp);
|
495
|
-
}
|
496
|
-
}
|
497
|
-
|
498
|
-
return ary;
|
499
|
-
}
|
500
|
-
|
501
|
-
/*
|
502
|
-
* call-seq:
|
503
|
-
* engine.inspect -> string
|
504
|
-
*
|
505
|
-
* Pretty prints this engine.
|
506
|
-
*/
|
507
|
-
static VALUE
|
508
|
-
ossl_engine_inspect(VALUE self)
|
509
|
-
{
|
510
|
-
ENGINE *e;
|
511
|
-
|
512
|
-
GetEngine(self, e);
|
513
|
-
return rb_sprintf("#<%"PRIsVALUE" id=\"%s\" name=\"%s\">",
|
514
|
-
rb_obj_class(self), ENGINE_get_id(e), ENGINE_get_name(e));
|
515
|
-
}
|
516
|
-
|
517
|
-
#define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x))
|
518
|
-
|
519
|
-
void
|
520
|
-
Init_ossl_engine(void)
|
521
|
-
{
|
522
|
-
#if 0
|
523
|
-
mOSSL = rb_define_module("OpenSSL");
|
524
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
525
|
-
#endif
|
526
|
-
|
527
|
-
cEngine = rb_define_class_under(mOSSL, "Engine", rb_cObject);
|
528
|
-
eEngineError = rb_define_class_under(cEngine, "EngineError", eOSSLError);
|
529
|
-
|
530
|
-
rb_undef_alloc_func(cEngine);
|
531
|
-
rb_define_singleton_method(cEngine, "load", ossl_engine_s_load, -1);
|
532
|
-
rb_define_singleton_method(cEngine, "cleanup", ossl_engine_s_cleanup, 0);
|
533
|
-
rb_define_singleton_method(cEngine, "engines", ossl_engine_s_engines, 0);
|
534
|
-
rb_define_singleton_method(cEngine, "by_id", ossl_engine_s_by_id, 1);
|
535
|
-
|
536
|
-
rb_define_method(cEngine, "id", ossl_engine_get_id, 0);
|
537
|
-
rb_define_method(cEngine, "name", ossl_engine_get_name, 0);
|
538
|
-
rb_define_method(cEngine, "finish", ossl_engine_finish, 0);
|
539
|
-
rb_define_method(cEngine, "cipher", ossl_engine_get_cipher, 1);
|
540
|
-
rb_define_method(cEngine, "digest", ossl_engine_get_digest, 1);
|
541
|
-
rb_define_method(cEngine, "load_private_key", ossl_engine_load_privkey, -1);
|
542
|
-
rb_define_method(cEngine, "load_public_key", ossl_engine_load_pubkey, -1);
|
543
|
-
rb_define_method(cEngine, "set_default", ossl_engine_set_default, 1);
|
544
|
-
rb_define_method(cEngine, "ctrl_cmd", ossl_engine_ctrl_cmd, -1);
|
545
|
-
rb_define_method(cEngine, "cmds", ossl_engine_get_cmds, 0);
|
546
|
-
rb_define_method(cEngine, "inspect", ossl_engine_inspect, 0);
|
547
|
-
|
548
|
-
DefEngineConst(METHOD_RSA);
|
549
|
-
DefEngineConst(METHOD_DSA);
|
550
|
-
DefEngineConst(METHOD_DH);
|
551
|
-
DefEngineConst(METHOD_RAND);
|
552
|
-
#ifdef ENGINE_METHOD_BN_MOD_EXP
|
553
|
-
DefEngineConst(METHOD_BN_MOD_EXP);
|
554
|
-
#endif
|
555
|
-
#ifdef ENGINE_METHOD_BN_MOD_EXP_CRT
|
556
|
-
DefEngineConst(METHOD_BN_MOD_EXP_CRT);
|
557
|
-
#endif
|
558
|
-
DefEngineConst(METHOD_CIPHERS);
|
559
|
-
DefEngineConst(METHOD_DIGESTS);
|
560
|
-
DefEngineConst(METHOD_ALL);
|
561
|
-
DefEngineConst(METHOD_NONE);
|
562
|
-
}
|
563
|
-
#else
|
564
|
-
void
|
565
|
-
Init_ossl_engine(void)
|
566
|
-
{
|
567
|
-
}
|
568
|
-
#endif
|
data/ext/openssl/ossl_engine.h
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* 'OpenSSL for Ruby' project
|
3
|
-
* Copyright (C) 2003 Michal Rokos <m.rokos@sh.cvut.cz>
|
4
|
-
* Copyright (C) 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
5
|
-
* All rights reserved.
|
6
|
-
*/
|
7
|
-
/*
|
8
|
-
* This program is licensed under the same licence as Ruby.
|
9
|
-
* (See the file 'LICENCE'.)
|
10
|
-
*/
|
11
|
-
#if !defined(OSSL_ENGINE_H)
|
12
|
-
#define OSSL_ENGINE_H
|
13
|
-
|
14
|
-
extern VALUE cEngine;
|
15
|
-
extern VALUE eEngineError;
|
16
|
-
|
17
|
-
void Init_ossl_engine(void);
|
18
|
-
|
19
|
-
#endif /* OSSL_ENGINE_H */
|