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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/mkmf.rb +5 -2
  3. data/lib/zig_example/version.rb +1 -1
  4. metadata +3 -56
  5. data/ext/openssl/openssl_missing.c +0 -40
  6. data/ext/openssl/openssl_missing.h +0 -238
  7. data/ext/openssl/ossl.c +0 -1295
  8. data/ext/openssl/ossl.h +0 -201
  9. data/ext/openssl/ossl_asn1.c +0 -1891
  10. data/ext/openssl/ossl_asn1.h +0 -62
  11. data/ext/openssl/ossl_bio.c +0 -42
  12. data/ext/openssl/ossl_bio.h +0 -16
  13. data/ext/openssl/ossl_bn.c +0 -1344
  14. data/ext/openssl/ossl_bn.h +0 -26
  15. data/ext/openssl/ossl_cipher.c +0 -1074
  16. data/ext/openssl/ossl_cipher.h +0 -20
  17. data/ext/openssl/ossl_config.c +0 -460
  18. data/ext/openssl/ossl_config.h +0 -16
  19. data/ext/openssl/ossl_digest.c +0 -425
  20. data/ext/openssl/ossl_digest.h +0 -20
  21. data/ext/openssl/ossl_engine.c +0 -568
  22. data/ext/openssl/ossl_engine.h +0 -19
  23. data/ext/openssl/ossl_hmac.c +0 -310
  24. data/ext/openssl/ossl_hmac.h +0 -18
  25. data/ext/openssl/ossl_kdf.c +0 -311
  26. data/ext/openssl/ossl_kdf.h +0 -6
  27. data/ext/openssl/ossl_ns_spki.c +0 -405
  28. data/ext/openssl/ossl_ns_spki.h +0 -19
  29. data/ext/openssl/ossl_ocsp.c +0 -1965
  30. data/ext/openssl/ossl_ocsp.h +0 -23
  31. data/ext/openssl/ossl_pkcs12.c +0 -275
  32. data/ext/openssl/ossl_pkcs12.h +0 -13
  33. data/ext/openssl/ossl_pkcs7.c +0 -1081
  34. data/ext/openssl/ossl_pkcs7.h +0 -36
  35. data/ext/openssl/ossl_pkey.c +0 -1624
  36. data/ext/openssl/ossl_pkey.h +0 -204
  37. data/ext/openssl/ossl_pkey_dh.c +0 -440
  38. data/ext/openssl/ossl_pkey_dsa.c +0 -359
  39. data/ext/openssl/ossl_pkey_ec.c +0 -1655
  40. data/ext/openssl/ossl_pkey_rsa.c +0 -579
  41. data/ext/openssl/ossl_rand.c +0 -200
  42. data/ext/openssl/ossl_rand.h +0 -18
  43. data/ext/openssl/ossl_ssl.c +0 -3142
  44. data/ext/openssl/ossl_ssl.h +0 -36
  45. data/ext/openssl/ossl_ssl_session.c +0 -331
  46. data/ext/openssl/ossl_ts.c +0 -1539
  47. data/ext/openssl/ossl_ts.h +0 -16
  48. data/ext/openssl/ossl_x509.c +0 -256
  49. data/ext/openssl/ossl_x509.h +0 -115
  50. data/ext/openssl/ossl_x509attr.c +0 -324
  51. data/ext/openssl/ossl_x509cert.c +0 -1002
  52. data/ext/openssl/ossl_x509crl.c +0 -545
  53. data/ext/openssl/ossl_x509ext.c +0 -490
  54. data/ext/openssl/ossl_x509name.c +0 -597
  55. data/ext/openssl/ossl_x509req.c +0 -444
  56. data/ext/openssl/ossl_x509revoked.c +0 -300
  57. data/ext/openssl/ossl_x509store.c +0 -986
@@ -1,545 +0,0 @@
1
- /*
2
- * 'OpenSSL for Ruby' project
3
- * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
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
- #define NewX509CRL(klass) \
13
- TypedData_Wrap_Struct((klass), &ossl_x509crl_type, 0)
14
- #define SetX509CRL(obj, crl) do { \
15
- if (!(crl)) { \
16
- ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
17
- } \
18
- RTYPEDDATA_DATA(obj) = (crl); \
19
- } while (0)
20
- #define GetX509CRL(obj, crl) do { \
21
- TypedData_Get_Struct((obj), X509_CRL, &ossl_x509crl_type, (crl)); \
22
- if (!(crl)) { \
23
- ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
24
- } \
25
- } while (0)
26
-
27
- /*
28
- * Classes
29
- */
30
- VALUE cX509CRL;
31
- VALUE eX509CRLError;
32
-
33
- static void
34
- ossl_x509crl_free(void *ptr)
35
- {
36
- X509_CRL_free(ptr);
37
- }
38
-
39
- static const rb_data_type_t ossl_x509crl_type = {
40
- "OpenSSL/X509/CRL",
41
- {
42
- 0, ossl_x509crl_free,
43
- },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
45
- };
46
-
47
- /*
48
- * PUBLIC
49
- */
50
- X509_CRL *
51
- GetX509CRLPtr(VALUE obj)
52
- {
53
- X509_CRL *crl;
54
-
55
- GetX509CRL(obj, crl);
56
-
57
- return crl;
58
- }
59
-
60
- VALUE
61
- ossl_x509crl_new(X509_CRL *crl)
62
- {
63
- X509_CRL *tmp;
64
- VALUE obj;
65
-
66
- obj = NewX509CRL(cX509CRL);
67
- tmp = crl ? X509_CRL_dup(crl) : X509_CRL_new();
68
- if(!tmp) ossl_raise(eX509CRLError, NULL);
69
- SetX509CRL(obj, tmp);
70
-
71
- return obj;
72
- }
73
-
74
- /*
75
- * PRIVATE
76
- */
77
- static VALUE
78
- ossl_x509crl_alloc(VALUE klass)
79
- {
80
- X509_CRL *crl;
81
- VALUE obj;
82
-
83
- obj = NewX509CRL(klass);
84
- if (!(crl = X509_CRL_new())) {
85
- ossl_raise(eX509CRLError, NULL);
86
- }
87
- SetX509CRL(obj, crl);
88
-
89
- return obj;
90
- }
91
-
92
- static VALUE
93
- ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
94
- {
95
- BIO *in;
96
- X509_CRL *crl, *crl_orig = RTYPEDDATA_DATA(self);
97
- VALUE arg;
98
-
99
- rb_check_frozen(self);
100
- if (rb_scan_args(argc, argv, "01", &arg) == 0) {
101
- return self;
102
- }
103
- arg = ossl_to_der_if_possible(arg);
104
- in = ossl_obj2bio(&arg);
105
- crl = d2i_X509_CRL_bio(in, NULL);
106
- if (!crl) {
107
- OSSL_BIO_reset(in);
108
- crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
109
- }
110
- BIO_free(in);
111
- if (!crl)
112
- ossl_raise(eX509CRLError, "PEM_read_bio_X509_CRL");
113
-
114
- RTYPEDDATA_DATA(self) = crl;
115
- X509_CRL_free(crl_orig);
116
-
117
- return self;
118
- }
119
-
120
- static VALUE
121
- ossl_x509crl_copy(VALUE self, VALUE other)
122
- {
123
- X509_CRL *a, *b, *crl;
124
-
125
- rb_check_frozen(self);
126
- if (self == other) return self;
127
- GetX509CRL(self, a);
128
- GetX509CRL(other, b);
129
- if (!(crl = X509_CRL_dup(b))) {
130
- ossl_raise(eX509CRLError, NULL);
131
- }
132
- X509_CRL_free(a);
133
- DATA_PTR(self) = crl;
134
-
135
- return self;
136
- }
137
-
138
- static VALUE
139
- ossl_x509crl_get_version(VALUE self)
140
- {
141
- X509_CRL *crl;
142
- long ver;
143
-
144
- GetX509CRL(self, crl);
145
- ver = X509_CRL_get_version(crl);
146
-
147
- return LONG2NUM(ver);
148
- }
149
-
150
- static VALUE
151
- ossl_x509crl_set_version(VALUE self, VALUE version)
152
- {
153
- X509_CRL *crl;
154
- long ver;
155
-
156
- if ((ver = NUM2LONG(version)) < 0) {
157
- ossl_raise(eX509CRLError, "version must be >= 0!");
158
- }
159
- GetX509CRL(self, crl);
160
- if (!X509_CRL_set_version(crl, ver)) {
161
- ossl_raise(eX509CRLError, NULL);
162
- }
163
-
164
- return version;
165
- }
166
-
167
- static VALUE
168
- ossl_x509crl_get_signature_algorithm(VALUE self)
169
- {
170
- X509_CRL *crl;
171
- const X509_ALGOR *alg;
172
- BIO *out;
173
-
174
- GetX509CRL(self, crl);
175
- if (!(out = BIO_new(BIO_s_mem()))) {
176
- ossl_raise(eX509CRLError, NULL);
177
- }
178
- X509_CRL_get0_signature(crl, NULL, &alg);
179
- if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
180
- BIO_free(out);
181
- ossl_raise(eX509CRLError, NULL);
182
- }
183
-
184
- return ossl_membio2str(out);
185
- }
186
-
187
- static VALUE
188
- ossl_x509crl_get_issuer(VALUE self)
189
- {
190
- X509_CRL *crl;
191
-
192
- GetX509CRL(self, crl);
193
-
194
- return ossl_x509name_new(X509_CRL_get_issuer(crl)); /* NO DUP - don't free */
195
- }
196
-
197
- static VALUE
198
- ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
199
- {
200
- X509_CRL *crl;
201
-
202
- GetX509CRL(self, crl);
203
-
204
- if (!X509_CRL_set_issuer_name(crl, GetX509NamePtr(issuer))) { /* DUPs name */
205
- ossl_raise(eX509CRLError, NULL);
206
- }
207
- return issuer;
208
- }
209
-
210
- static VALUE
211
- ossl_x509crl_get_last_update(VALUE self)
212
- {
213
- X509_CRL *crl;
214
- const ASN1_TIME *time;
215
-
216
- GetX509CRL(self, crl);
217
- time = X509_CRL_get0_lastUpdate(crl);
218
- if (!time)
219
- return Qnil;
220
-
221
- return asn1time_to_time(time);
222
- }
223
-
224
- static VALUE
225
- ossl_x509crl_set_last_update(VALUE self, VALUE time)
226
- {
227
- X509_CRL *crl;
228
- ASN1_TIME *asn1time;
229
-
230
- GetX509CRL(self, crl);
231
- asn1time = ossl_x509_time_adjust(NULL, time);
232
- if (!X509_CRL_set1_lastUpdate(crl, asn1time)) {
233
- ASN1_TIME_free(asn1time);
234
- ossl_raise(eX509CRLError, "X509_CRL_set_lastUpdate");
235
- }
236
- ASN1_TIME_free(asn1time);
237
-
238
- return time;
239
- }
240
-
241
- static VALUE
242
- ossl_x509crl_get_next_update(VALUE self)
243
- {
244
- X509_CRL *crl;
245
- const ASN1_TIME *time;
246
-
247
- GetX509CRL(self, crl);
248
- time = X509_CRL_get0_nextUpdate(crl);
249
- if (!time)
250
- return Qnil;
251
-
252
- return asn1time_to_time(time);
253
- }
254
-
255
- static VALUE
256
- ossl_x509crl_set_next_update(VALUE self, VALUE time)
257
- {
258
- X509_CRL *crl;
259
- ASN1_TIME *asn1time;
260
-
261
- GetX509CRL(self, crl);
262
- asn1time = ossl_x509_time_adjust(NULL, time);
263
- if (!X509_CRL_set1_nextUpdate(crl, asn1time)) {
264
- ASN1_TIME_free(asn1time);
265
- ossl_raise(eX509CRLError, "X509_CRL_set_nextUpdate");
266
- }
267
- ASN1_TIME_free(asn1time);
268
-
269
- return time;
270
- }
271
-
272
- static VALUE
273
- ossl_x509crl_get_revoked(VALUE self)
274
- {
275
- X509_CRL *crl;
276
- int i, num;
277
- X509_REVOKED *rev;
278
- VALUE ary, revoked;
279
-
280
- GetX509CRL(self, crl);
281
- num = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
282
- if (num < 0) {
283
- OSSL_Debug("num < 0???");
284
- return rb_ary_new();
285
- }
286
- ary = rb_ary_new2(num);
287
- for(i=0; i<num; i++) {
288
- /* NO DUP - don't free! */
289
- rev = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
290
- revoked = ossl_x509revoked_new(rev);
291
- rb_ary_push(ary, revoked);
292
- }
293
-
294
- return ary;
295
- }
296
-
297
- static VALUE
298
- ossl_x509crl_set_revoked(VALUE self, VALUE ary)
299
- {
300
- X509_CRL *crl;
301
- X509_REVOKED *rev;
302
- STACK_OF(X509_REVOKED) *sk;
303
- long i;
304
-
305
- Check_Type(ary, T_ARRAY);
306
- /* All ary members should be X509 Revoked */
307
- for (i=0; i<RARRAY_LEN(ary); i++) {
308
- OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Rev);
309
- }
310
- GetX509CRL(self, crl);
311
- if ((sk = X509_CRL_get_REVOKED(crl))) {
312
- while ((rev = sk_X509_REVOKED_pop(sk)))
313
- X509_REVOKED_free(rev);
314
- }
315
- for (i=0; i<RARRAY_LEN(ary); i++) {
316
- rev = DupX509RevokedPtr(RARRAY_AREF(ary, i));
317
- if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
318
- X509_REVOKED_free(rev);
319
- ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
320
- }
321
- }
322
- X509_CRL_sort(crl);
323
-
324
- return ary;
325
- }
326
-
327
- static VALUE
328
- ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
329
- {
330
- X509_CRL *crl;
331
- X509_REVOKED *rev;
332
-
333
- GetX509CRL(self, crl);
334
- rev = DupX509RevokedPtr(revoked);
335
- if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
336
- X509_REVOKED_free(rev);
337
- ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
338
- }
339
- X509_CRL_sort(crl);
340
-
341
- return revoked;
342
- }
343
-
344
- static VALUE
345
- ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
346
- {
347
- X509_CRL *crl;
348
- EVP_PKEY *pkey;
349
- const EVP_MD *md;
350
-
351
- GetX509CRL(self, crl);
352
- pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
353
- md = ossl_evp_get_digestbyname(digest);
354
- if (!X509_CRL_sign(crl, pkey, md)) {
355
- ossl_raise(eX509CRLError, NULL);
356
- }
357
-
358
- return self;
359
- }
360
-
361
- static VALUE
362
- ossl_x509crl_verify(VALUE self, VALUE key)
363
- {
364
- X509_CRL *crl;
365
- EVP_PKEY *pkey;
366
-
367
- GetX509CRL(self, crl);
368
- pkey = GetPKeyPtr(key);
369
- ossl_pkey_check_public_key(pkey);
370
- switch (X509_CRL_verify(crl, pkey)) {
371
- case 1:
372
- return Qtrue;
373
- case 0:
374
- ossl_clear_error();
375
- return Qfalse;
376
- default:
377
- ossl_raise(eX509CRLError, NULL);
378
- }
379
- }
380
-
381
- static VALUE
382
- ossl_x509crl_to_der(VALUE self)
383
- {
384
- X509_CRL *crl;
385
- BIO *out;
386
-
387
- GetX509CRL(self, crl);
388
- if (!(out = BIO_new(BIO_s_mem()))) {
389
- ossl_raise(eX509CRLError, NULL);
390
- }
391
- if (!i2d_X509_CRL_bio(out, crl)) {
392
- BIO_free(out);
393
- ossl_raise(eX509CRLError, NULL);
394
- }
395
-
396
- return ossl_membio2str(out);
397
- }
398
-
399
- static VALUE
400
- ossl_x509crl_to_pem(VALUE self)
401
- {
402
- X509_CRL *crl;
403
- BIO *out;
404
-
405
- GetX509CRL(self, crl);
406
- if (!(out = BIO_new(BIO_s_mem()))) {
407
- ossl_raise(eX509CRLError, NULL);
408
- }
409
- if (!PEM_write_bio_X509_CRL(out, crl)) {
410
- BIO_free(out);
411
- ossl_raise(eX509CRLError, NULL);
412
- }
413
-
414
- return ossl_membio2str(out);
415
- }
416
-
417
- static VALUE
418
- ossl_x509crl_to_text(VALUE self)
419
- {
420
- X509_CRL *crl;
421
- BIO *out;
422
-
423
- GetX509CRL(self, crl);
424
- if (!(out = BIO_new(BIO_s_mem()))) {
425
- ossl_raise(eX509CRLError, NULL);
426
- }
427
- if (!X509_CRL_print(out, crl)) {
428
- BIO_free(out);
429
- ossl_raise(eX509CRLError, NULL);
430
- }
431
-
432
- return ossl_membio2str(out);
433
- }
434
-
435
- /*
436
- * Gets X509v3 extensions as array of X509Ext objects
437
- */
438
- static VALUE
439
- ossl_x509crl_get_extensions(VALUE self)
440
- {
441
- X509_CRL *crl;
442
- int count, i;
443
- X509_EXTENSION *ext;
444
- VALUE ary;
445
-
446
- GetX509CRL(self, crl);
447
- count = X509_CRL_get_ext_count(crl);
448
- if (count < 0) {
449
- OSSL_Debug("count < 0???");
450
- return rb_ary_new();
451
- }
452
- ary = rb_ary_new2(count);
453
- for (i=0; i<count; i++) {
454
- ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
455
- rb_ary_push(ary, ossl_x509ext_new(ext));
456
- }
457
-
458
- return ary;
459
- }
460
-
461
- /*
462
- * Sets X509_EXTENSIONs
463
- */
464
- static VALUE
465
- ossl_x509crl_set_extensions(VALUE self, VALUE ary)
466
- {
467
- X509_CRL *crl;
468
- X509_EXTENSION *ext;
469
- long i;
470
-
471
- Check_Type(ary, T_ARRAY);
472
- /* All ary members should be X509 Extensions */
473
- for (i=0; i<RARRAY_LEN(ary); i++) {
474
- OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
475
- }
476
- GetX509CRL(self, crl);
477
- for (i = X509_CRL_get_ext_count(crl); i > 0; i--)
478
- X509_EXTENSION_free(X509_CRL_delete_ext(crl, 0));
479
- for (i=0; i<RARRAY_LEN(ary); i++) {
480
- ext = GetX509ExtPtr(RARRAY_AREF(ary, i)); /* NO NEED TO DUP */
481
- if (!X509_CRL_add_ext(crl, ext, -1)) {
482
- ossl_raise(eX509CRLError, "X509_CRL_add_ext");
483
- }
484
- }
485
-
486
- return ary;
487
- }
488
-
489
- static VALUE
490
- ossl_x509crl_add_extension(VALUE self, VALUE extension)
491
- {
492
- X509_CRL *crl;
493
- X509_EXTENSION *ext;
494
-
495
- GetX509CRL(self, crl);
496
- ext = GetX509ExtPtr(extension);
497
- if (!X509_CRL_add_ext(crl, ext, -1)) {
498
- ossl_raise(eX509CRLError, NULL);
499
- }
500
-
501
- return extension;
502
- }
503
-
504
- /*
505
- * INIT
506
- */
507
- void
508
- Init_ossl_x509crl(void)
509
- {
510
- #if 0
511
- mOSSL = rb_define_module("OpenSSL");
512
- eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
513
- mX509 = rb_define_module_under(mOSSL, "X509");
514
- #endif
515
-
516
- eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError);
517
-
518
- cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject);
519
-
520
- rb_define_alloc_func(cX509CRL, ossl_x509crl_alloc);
521
- rb_define_method(cX509CRL, "initialize", ossl_x509crl_initialize, -1);
522
- rb_define_method(cX509CRL, "initialize_copy", ossl_x509crl_copy, 1);
523
-
524
- rb_define_method(cX509CRL, "version", ossl_x509crl_get_version, 0);
525
- rb_define_method(cX509CRL, "version=", ossl_x509crl_set_version, 1);
526
- rb_define_method(cX509CRL, "signature_algorithm", ossl_x509crl_get_signature_algorithm, 0);
527
- rb_define_method(cX509CRL, "issuer", ossl_x509crl_get_issuer, 0);
528
- rb_define_method(cX509CRL, "issuer=", ossl_x509crl_set_issuer, 1);
529
- rb_define_method(cX509CRL, "last_update", ossl_x509crl_get_last_update, 0);
530
- rb_define_method(cX509CRL, "last_update=", ossl_x509crl_set_last_update, 1);
531
- rb_define_method(cX509CRL, "next_update", ossl_x509crl_get_next_update, 0);
532
- rb_define_method(cX509CRL, "next_update=", ossl_x509crl_set_next_update, 1);
533
- rb_define_method(cX509CRL, "revoked", ossl_x509crl_get_revoked, 0);
534
- rb_define_method(cX509CRL, "revoked=", ossl_x509crl_set_revoked, 1);
535
- rb_define_method(cX509CRL, "add_revoked", ossl_x509crl_add_revoked, 1);
536
- rb_define_method(cX509CRL, "sign", ossl_x509crl_sign, 2);
537
- rb_define_method(cX509CRL, "verify", ossl_x509crl_verify, 1);
538
- rb_define_method(cX509CRL, "to_der", ossl_x509crl_to_der, 0);
539
- rb_define_method(cX509CRL, "to_pem", ossl_x509crl_to_pem, 0);
540
- rb_define_alias(cX509CRL, "to_s", "to_pem");
541
- rb_define_method(cX509CRL, "to_text", ossl_x509crl_to_text, 0);
542
- rb_define_method(cX509CRL, "extensions", ossl_x509crl_get_extensions, 0);
543
- rb_define_method(cX509CRL, "extensions=", ossl_x509crl_set_extensions, 1);
544
- rb_define_method(cX509CRL, "add_extension", ossl_x509crl_add_extension, 1);
545
- }