rubysl-openssl 2.10 → 2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/ext/rubysl/openssl/deprecation.rb +7 -3
  3. data/ext/rubysl/openssl/extconf.rb +148 -103
  4. data/ext/rubysl/openssl/openssl_missing.c +94 -275
  5. data/ext/rubysl/openssl/openssl_missing.h +167 -98
  6. data/ext/rubysl/openssl/ossl.c +266 -212
  7. data/ext/rubysl/openssl/ossl.h +27 -89
  8. data/ext/rubysl/openssl/ossl_asn1.c +157 -221
  9. data/ext/rubysl/openssl/ossl_asn1.h +11 -3
  10. data/ext/rubysl/openssl/ossl_bio.c +10 -40
  11. data/ext/rubysl/openssl/ossl_bio.h +1 -2
  12. data/ext/rubysl/openssl/ossl_bn.c +144 -100
  13. data/ext/rubysl/openssl/ossl_bn.h +3 -1
  14. data/ext/rubysl/openssl/ossl_cipher.c +270 -195
  15. data/ext/rubysl/openssl/ossl_config.c +7 -1
  16. data/ext/rubysl/openssl/ossl_config.h +0 -1
  17. data/ext/rubysl/openssl/ossl_digest.c +40 -29
  18. data/ext/rubysl/openssl/ossl_engine.c +23 -62
  19. data/ext/rubysl/openssl/ossl_hmac.c +82 -55
  20. data/ext/rubysl/openssl/ossl_ns_spki.c +22 -22
  21. data/ext/rubysl/openssl/ossl_ocsp.c +894 -144
  22. data/ext/rubysl/openssl/ossl_ocsp.h +1 -1
  23. data/ext/rubysl/openssl/ossl_pkcs12.c +47 -19
  24. data/ext/rubysl/openssl/ossl_pkcs5.c +7 -15
  25. data/ext/rubysl/openssl/ossl_pkcs7.c +38 -15
  26. data/ext/rubysl/openssl/ossl_pkey.c +151 -99
  27. data/ext/rubysl/openssl/ossl_pkey.h +123 -29
  28. data/ext/rubysl/openssl/ossl_pkey_dh.c +143 -92
  29. data/ext/rubysl/openssl/ossl_pkey_dsa.c +149 -104
  30. data/ext/rubysl/openssl/ossl_pkey_ec.c +646 -524
  31. data/ext/rubysl/openssl/ossl_pkey_rsa.c +180 -121
  32. data/ext/rubysl/openssl/ossl_rand.c +25 -21
  33. data/ext/rubysl/openssl/ossl_ssl.c +795 -413
  34. data/ext/rubysl/openssl/ossl_ssl.h +3 -0
  35. data/ext/rubysl/openssl/ossl_ssl_session.c +83 -77
  36. data/ext/rubysl/openssl/ossl_version.h +1 -1
  37. data/ext/rubysl/openssl/ossl_x509.c +92 -8
  38. data/ext/rubysl/openssl/ossl_x509.h +14 -5
  39. data/ext/rubysl/openssl/ossl_x509attr.c +77 -41
  40. data/ext/rubysl/openssl/ossl_x509cert.c +45 -46
  41. data/ext/rubysl/openssl/ossl_x509crl.c +51 -57
  42. data/ext/rubysl/openssl/ossl_x509ext.c +39 -33
  43. data/ext/rubysl/openssl/ossl_x509name.c +68 -45
  44. data/ext/rubysl/openssl/ossl_x509req.c +32 -38
  45. data/ext/rubysl/openssl/ossl_x509revoked.c +43 -9
  46. data/ext/rubysl/openssl/ossl_x509store.c +309 -104
  47. data/ext/rubysl/openssl/ruby_missing.h +8 -6
  48. data/lib/openssl/buffering.rb +11 -5
  49. data/lib/openssl/cipher.rb +23 -15
  50. data/lib/openssl/digest.rb +7 -10
  51. data/lib/openssl/pkey.rb +15 -8
  52. data/lib/openssl/ssl.rb +81 -105
  53. data/lib/rubysl/openssl.rb +1 -4
  54. data/lib/rubysl/openssl/version.rb +1 -1
  55. metadata +3 -4
@@ -12,49 +12,14 @@
12
12
 
13
13
  #include RUBY_EXTCONF_H
14
14
 
15
- #if defined(__cplusplus)
16
- extern "C" {
17
- #endif
18
-
19
- #if 0
20
- mOSSL = rb_define_module("OpenSSL");
21
- mX509 = rb_define_module_under(mOSSL, "X509");
22
- #endif
23
-
24
- /*
25
- * OpenSSL has defined RFILE and Ruby has defined RFILE - so undef it!
26
- */
27
- #if defined(RFILE) /*&& !defined(OSSL_DEBUG)*/
28
- # undef RFILE
29
- #endif
15
+ #include <assert.h>
16
+ #include <errno.h>
30
17
  #include <ruby.h>
31
18
  #include <ruby/io.h>
32
19
  #include <ruby/thread.h>
33
-
34
- /*
35
- * Check the OpenSSL version
36
- * The only supported are:
37
- * OpenSSL >= 0.9.7
38
- */
39
20
  #include <openssl/opensslv.h>
40
-
41
- #ifdef HAVE_ASSERT_H
42
- # include <assert.h>
43
- #else
44
- # define assert(condition)
45
- #endif
46
-
47
- #if defined(_WIN32) && !defined(LIBRESSL_VERSION_NUMBER)
48
- # include <openssl/e_os2.h>
49
- # define OSSL_NO_CONF_API 1
50
- # if !defined(OPENSSL_SYS_WIN32)
51
- # define OPENSSL_SYS_WIN32 1
52
- # endif
53
- # include <winsock2.h>
54
- #endif
55
- #include <errno.h>
56
21
  #include <openssl/err.h>
57
- #include <openssl/asn1_mac.h>
22
+ #include <openssl/asn1.h>
58
23
  #include <openssl/x509v3.h>
59
24
  #include <openssl/ssl.h>
60
25
  #include <openssl/pkcs12.h>
@@ -63,25 +28,14 @@ extern "C" {
63
28
  #include <openssl/rand.h>
64
29
  #include <openssl/conf.h>
65
30
  #include <openssl/conf_api.h>
66
- #if !defined(_WIN32)
67
- # include <openssl/crypto.h>
68
- #endif
69
- #undef X509_NAME
70
- #undef PKCS7_SIGNER_INFO
71
- #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_EVP_CIPHER_CTX_ENGINE)
72
- # define OSSL_ENGINE_ENABLED
31
+ #include <openssl/crypto.h>
32
+ #if !defined(OPENSSL_NO_ENGINE)
73
33
  # include <openssl/engine.h>
74
34
  #endif
75
- #if defined(HAVE_OPENSSL_OCSP_H)
76
- # define OSSL_OCSP_ENABLED
35
+ #if !defined(OPENSSL_NO_OCSP)
77
36
  # include <openssl/ocsp.h>
78
37
  #endif
79
38
 
80
- /* OpenSSL requires passwords for PEM-encoded files to be at least four
81
- * characters long
82
- */
83
- #define OSSL_MIN_PWD_LEN 4
84
-
85
39
  /*
86
40
  * Common Module
87
41
  */
@@ -115,27 +69,15 @@ extern VALUE eOSSLError;
115
69
  }\
116
70
  } while (0)
117
71
 
118
- /*
119
- * Compatibility
120
- */
121
- #if OPENSSL_VERSION_NUMBER >= 0x10000000L
122
- #define STACK _STACK
123
- #endif
124
-
125
- /*
126
- * String to HEXString conversion
127
- */
128
- int string2hex(const unsigned char *, int, char **, int *);
129
-
130
72
  /*
131
73
  * Data Conversion
132
74
  */
133
75
  STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
134
76
  STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
135
77
  STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
136
- VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
137
- VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
138
- VALUE ossl_x509name_sk2ary(STACK_OF(X509_NAME) *names);
78
+ VALUE ossl_x509_sk2ary(const STACK_OF(X509) *certs);
79
+ VALUE ossl_x509crl_sk2ary(const STACK_OF(X509_CRL) *crl);
80
+ VALUE ossl_x509name_sk2ary(const STACK_OF(X509_NAME) *names);
139
81
  VALUE ossl_buf2str(char *buf, int len);
140
82
  #define ossl_str_adjust(str, p) \
141
83
  do{\
@@ -144,39 +86,39 @@ do{\
144
86
  assert(newlen <= len);\
145
87
  rb_str_set_len((str), newlen);\
146
88
  }while(0)
89
+ /*
90
+ * Convert binary string to hex string. The caller is responsible for
91
+ * ensuring out has (2 * len) bytes of capacity.
92
+ */
93
+ void ossl_bin2hex(unsigned char *in, char *out, size_t len);
147
94
 
148
95
  /*
149
- * our default PEM callback
96
+ * Our default PEM callback
150
97
  */
98
+ /* Convert the argument to String and validate the length. Note this may raise. */
99
+ VALUE ossl_pem_passwd_value(VALUE);
100
+ /* Can be casted to pem_password_cb. If a password (String) is passed as the
101
+ * "arbitrary data" (typically the last parameter of PEM_{read,write}_
102
+ * functions), uses the value. If not, but a block is given, yields to it.
103
+ * If not either, fallbacks to PEM_def_callback() which reads from stdin. */
151
104
  int ossl_pem_passwd_cb(char *, int, int, void *);
152
105
 
153
106
  /*
154
107
  * Clear BIO* with this in PEM/DER fallback scenarios to avoid decoding
155
108
  * errors piling up in OpenSSL::Errors
156
109
  */
157
- #define OSSL_BIO_reset(bio) (void)BIO_reset((bio)); \
158
- ERR_clear_error();
110
+ #define OSSL_BIO_reset(bio) do { \
111
+ (void)BIO_reset((bio)); \
112
+ ossl_clear_error(); \
113
+ } while (0)
159
114
 
160
115
  /*
161
116
  * ERRor messages
162
117
  */
163
118
  #define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
164
119
  NORETURN(void ossl_raise(VALUE, const char *, ...));
165
- VALUE ossl_exc_new(VALUE, const char *, ...);
166
-
167
- /*
168
- * Verify callback
169
- */
170
- extern int ossl_verify_cb_idx;
171
-
172
- struct ossl_verify_cb_args {
173
- VALUE proc;
174
- VALUE preverify_ok;
175
- VALUE store_ctx;
176
- };
177
-
178
- VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *);
179
- int ossl_verify_cb(int, X509_STORE_CTX *);
120
+ /* Clear OpenSSL error queue. If dOSSL is set, rb_warn() them. */
121
+ void ossl_clear_error(void);
180
122
 
181
123
  /*
182
124
  * String to DER String
@@ -241,8 +183,4 @@ void ossl_debug(const char *, ...);
241
183
 
242
184
  void Init_openssl(void);
243
185
 
244
- #if defined(__cplusplus)
245
- }
246
- #endif
247
-
248
186
  #endif /* _OSSL_H_ */
@@ -9,15 +9,6 @@
9
9
  */
10
10
  #include "ossl.h"
11
11
 
12
- #if defined(HAVE_SYS_TIME_H)
13
- # include <sys/time.h>
14
- #elif !defined(NT) && !defined(_WIN32)
15
- struct timeval {
16
- long tv_sec; /* seconds */
17
- long tv_usec; /* and microseconds */
18
- };
19
- #endif
20
-
21
12
  static VALUE join_der(VALUE enumerable);
22
13
  static VALUE ossl_asn1_decode0(unsigned char **pp, long length, long *offset,
23
14
  int depth, int yield, long *num_read);
@@ -28,7 +19,7 @@ static VALUE ossl_asn1eoc_initialize(VALUE self);
28
19
  * DATE conversion
29
20
  */
30
21
  VALUE
31
- asn1time_to_time(ASN1_TIME *time)
22
+ asn1time_to_time(const ASN1_TIME *time)
32
23
  {
33
24
  struct tm tm;
34
25
  VALUE argv[6];
@@ -56,9 +47,15 @@ asn1time_to_time(ASN1_TIME *time)
56
47
  }
57
48
  break;
58
49
  case V_ASN1_GENERALIZEDTIME:
59
- if (sscanf((const char *)time->data, "%4d%2d%2d%2d%2d%2dZ", &tm.tm_year, &tm.tm_mon,
60
- &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
61
- ossl_raise(rb_eTypeError, "bad GENERALIZEDTIME format" );
50
+ count = sscanf((const char *)time->data, "%4d%2d%2d%2d%2d%2dZ",
51
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
52
+ &tm.tm_sec);
53
+ if (count == 5) {
54
+ tm.tm_sec = 0;
55
+ }
56
+ else if (count != 6) {
57
+ ossl_raise(rb_eTypeError, "bad GENERALIZEDTIME format: \"%s\"",
58
+ time->data);
62
59
  }
63
60
  break;
64
61
  default:
@@ -75,83 +72,65 @@ asn1time_to_time(ASN1_TIME *time)
75
72
  return rb_funcall2(rb_cTime, rb_intern("utc"), 6, argv);
76
73
  }
77
74
 
78
- /*
79
- * This function is not exported in Ruby's *.h
80
- */
81
- extern struct timeval rb_time_timeval(VALUE);
75
+ #if defined(HAVE_ASN1_TIME_ADJ)
76
+ void
77
+ ossl_time_split(VALUE time, time_t *sec, int *days)
78
+ {
79
+ VALUE num = rb_Integer(time);
82
80
 
81
+ if (FIXNUM_P(num)) {
82
+ time_t t = FIX2LONG(num);
83
+ *sec = t % 86400;
84
+ *days = rb_long2int(t / 86400);
85
+ }
86
+ else {
87
+ *days = NUM2INT(rb_funcall(num, rb_intern("/"), 1, INT2FIX(86400)));
88
+ *sec = NUM2TIMET(rb_funcall(num, rb_intern("%"), 1, INT2FIX(86400)));
89
+ }
90
+ }
91
+ #else
83
92
  time_t
84
93
  time_to_time_t(VALUE time)
85
94
  {
86
- return (time_t)NUM2LONG(rb_Integer(time));
95
+ return (time_t)NUM2TIMET(rb_Integer(time));
87
96
  }
97
+ #endif
88
98
 
89
99
  /*
90
100
  * STRING conversion
91
101
  */
92
102
  VALUE
93
- asn1str_to_str(ASN1_STRING *str)
103
+ asn1str_to_str(const ASN1_STRING *str)
94
104
  {
95
105
  return rb_str_new((const char *)str->data, str->length);
96
106
  }
97
107
 
98
108
  /*
99
109
  * ASN1_INTEGER conversions
100
- * TODO: Make a decision what's the right way to do this.
101
110
  */
102
- #define DO_IT_VIA_RUBY 0
103
111
  VALUE
104
- asn1integer_to_num(ASN1_INTEGER *ai)
112
+ asn1integer_to_num(const ASN1_INTEGER *ai)
105
113
  {
106
114
  BIGNUM *bn;
107
- #if DO_IT_VIA_RUBY
108
- char *txt;
109
- #endif
110
115
  VALUE num;
111
116
 
112
117
  if (!ai) {
113
118
  ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
114
119
  }
115
- if (!(bn = ASN1_INTEGER_to_BN(ai, NULL))) {
116
- ossl_raise(eOSSLError, NULL);
117
- }
118
- #if DO_IT_VIA_RUBY
119
- if (!(txt = BN_bn2dec(bn))) {
120
- BN_free(bn);
120
+ if (ai->type == V_ASN1_ENUMERATED)
121
+ /* const_cast: workaround for old OpenSSL */
122
+ bn = ASN1_ENUMERATED_to_BN((ASN1_ENUMERATED *)ai, NULL);
123
+ else
124
+ bn = ASN1_INTEGER_to_BN(ai, NULL);
125
+
126
+ if (!bn)
121
127
  ossl_raise(eOSSLError, NULL);
122
- }
123
- num = rb_cstr_to_inum(txt, 10, Qtrue);
124
- OPENSSL_free(txt);
125
- #else
126
128
  num = ossl_bn_new(bn);
127
- #endif
128
129
  BN_free(bn);
129
130
 
130
131
  return num;
131
132
  }
132
133
 
133
- #if DO_IT_VIA_RUBY
134
- ASN1_INTEGER *
135
- num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
136
- {
137
- BIGNUM *bn = NULL;
138
-
139
- if (RTEST(rb_obj_is_kind_of(obj, cBN))) {
140
- bn = GetBNPtr(obj);
141
- } else {
142
- obj = rb_String(obj);
143
- if (!BN_dec2bn(&bn, StringValuePtr(obj))) {
144
- ossl_raise(eOSSLError, NULL);
145
- }
146
- }
147
- if (!(ai = BN_to_ASN1_INTEGER(bn, ai))) {
148
- BN_free(bn);
149
- ossl_raise(eOSSLError, NULL);
150
- }
151
- BN_free(bn);
152
- return ai;
153
- }
154
- #else
155
134
  ASN1_INTEGER *
156
135
  num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
157
136
  {
@@ -167,7 +146,6 @@ num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
167
146
 
168
147
  return ai;
169
148
  }
170
- #endif
171
149
 
172
150
  /********/
173
151
  /*
@@ -207,22 +185,10 @@ VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
207
185
  VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
208
186
  VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
209
187
 
210
- static ID sIMPLICIT, sEXPLICIT;
211
- static ID sUNIVERSAL, sAPPLICATION, sCONTEXT_SPECIFIC, sPRIVATE;
188
+ static VALUE sym_IMPLICIT, sym_EXPLICIT;
189
+ static VALUE sym_UNIVERSAL, sym_APPLICATION, sym_CONTEXT_SPECIFIC, sym_PRIVATE;
212
190
  static ID sivVALUE, sivTAG, sivTAG_CLASS, sivTAGGING, sivINFINITE_LENGTH, sivUNUSED_BITS;
213
-
214
- /*
215
- * We need to implement these for backward compatibility
216
- * reasons, behavior of ASN1_put_object and ASN1_object_size
217
- * for infinite length values is different in OpenSSL <= 0.9.7
218
- */
219
- #if OPENSSL_VERSION_NUMBER < 0x00908000L
220
- #define ossl_asn1_object_size(cons, len, tag) (cons) == 2 ? (len) + ASN1_object_size((cons), 0, (tag)) : ASN1_object_size((cons), (len), (tag))
221
- #define ossl_asn1_put_object(pp, cons, len, tag, xc) (cons) == 2 ? ASN1_put_object((pp), (cons), 0, (tag), (xc)) : ASN1_put_object((pp), (cons), (len), (tag), (xc))
222
- #else
223
- #define ossl_asn1_object_size(cons, len, tag) ASN1_object_size((cons), (len), (tag))
224
- #define ossl_asn1_put_object(pp, cons, len, tag, xc) ASN1_put_object((pp), (cons), (len), (tag), (xc))
225
- #endif
191
+ static ID id_each;
226
192
 
227
193
  /*
228
194
  * Ruby to ASN1 converters
@@ -233,11 +199,7 @@ obj_to_asn1bool(VALUE obj)
233
199
  if (NIL_P(obj))
234
200
  ossl_raise(rb_eTypeError, "Can't convert nil into Boolean");
235
201
 
236
- #if OPENSSL_VERSION_NUMBER < 0x00907000L
237
- return RTEST(obj) ? 0xff : 0x100;
238
- #else
239
202
  return RTEST(obj) ? 0xff : 0x0;
240
- #endif
241
203
  }
242
204
 
243
205
  static ASN1_INTEGER*
@@ -293,36 +255,50 @@ obj_to_asn1obj(VALUE obj)
293
255
  {
294
256
  ASN1_OBJECT *a1obj;
295
257
 
296
- StringValue(obj);
258
+ StringValueCStr(obj);
297
259
  a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 0);
298
260
  if(!a1obj) a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 1);
299
- if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID");
261
+ if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID %"PRIsVALUE, obj);
300
262
 
301
263
  return a1obj;
302
264
  }
303
265
 
304
- static ASN1_UTCTIME*
266
+ static ASN1_UTCTIME *
305
267
  obj_to_asn1utime(VALUE time)
306
268
  {
307
269
  time_t sec;
308
270
  ASN1_UTCTIME *t;
309
271
 
272
+ #if defined(HAVE_ASN1_TIME_ADJ)
273
+ int off_days;
274
+
275
+ ossl_time_split(time, &sec, &off_days);
276
+ if (!(t = ASN1_UTCTIME_adj(NULL, sec, off_days, 0)))
277
+ #else
310
278
  sec = time_to_time_t(time);
311
- if(!(t = ASN1_UTCTIME_set(NULL, sec)))
312
- ossl_raise(eASN1Error, NULL);
279
+ if (!(t = ASN1_UTCTIME_set(NULL, sec)))
280
+ #endif
281
+ ossl_raise(eASN1Error, NULL);
313
282
 
314
283
  return t;
315
284
  }
316
285
 
317
- static ASN1_GENERALIZEDTIME*
286
+ static ASN1_GENERALIZEDTIME *
318
287
  obj_to_asn1gtime(VALUE time)
319
288
  {
320
289
  time_t sec;
321
290
  ASN1_GENERALIZEDTIME *t;
322
291
 
292
+ #if defined(HAVE_ASN1_TIME_ADJ)
293
+ int off_days;
294
+
295
+ ossl_time_split(time, &sec, &off_days);
296
+ if (!(t = ASN1_GENERALIZEDTIME_adj(NULL, sec, off_days, 0)))
297
+ #else
323
298
  sec = time_to_time_t(time);
324
- if(!(t =ASN1_GENERALIZEDTIME_set(NULL, sec)))
325
- ossl_raise(eASN1Error, NULL);
299
+ if (!(t = ASN1_GENERALIZEDTIME_set(NULL, sec)))
300
+ #endif
301
+ ossl_raise(eASN1Error, NULL);
326
302
 
327
303
  return t;
328
304
  }
@@ -347,14 +323,14 @@ obj_to_asn1derstr(VALUE obj)
347
323
  static VALUE
348
324
  decode_bool(unsigned char* der, long length)
349
325
  {
350
- int val;
351
- const unsigned char *p;
326
+ const unsigned char *p = der;
352
327
 
353
- p = der;
354
- if((val = d2i_ASN1_BOOLEAN(NULL, &p, length)) < 0)
355
- ossl_raise(eASN1Error, NULL);
328
+ if (length != 3)
329
+ ossl_raise(eASN1Error, "invalid length for BOOLEAN");
330
+ if (p[0] != 1 || p[1] != 1)
331
+ ossl_raise(eASN1Error, "invalid BOOLEAN");
356
332
 
357
- return val ? Qtrue : Qfalse;
333
+ return p[2] ? Qtrue : Qfalse;
358
334
  }
359
335
 
360
336
  static VALUE
@@ -368,7 +344,7 @@ decode_int(unsigned char* der, long length)
368
344
  p = der;
369
345
  if(!(ai = d2i_ASN1_INTEGER(NULL, &p, length)))
370
346
  ossl_raise(eASN1Error, NULL);
371
- ret = rb_protect((VALUE(*)_((VALUE)))asn1integer_to_num,
347
+ ret = rb_protect((VALUE (*)(VALUE))asn1integer_to_num,
372
348
  (VALUE)ai, &status);
373
349
  ASN1_INTEGER_free(ai);
374
350
  if(status) rb_jump_tag(status);
@@ -408,7 +384,7 @@ decode_enum(unsigned char* der, long length)
408
384
  p = der;
409
385
  if(!(ai = d2i_ASN1_ENUMERATED(NULL, &p, length)))
410
386
  ossl_raise(eASN1Error, NULL);
411
- ret = rb_protect((VALUE(*)_((VALUE)))asn1integer_to_num,
387
+ ret = rb_protect((VALUE (*)(VALUE))asn1integer_to_num,
412
388
  (VALUE)ai, &status);
413
389
  ASN1_ENUMERATED_free(ai);
414
390
  if(status) rb_jump_tag(status);
@@ -470,7 +446,7 @@ decode_time(unsigned char* der, long length)
470
446
  p = der;
471
447
  if(!(time = d2i_ASN1_TIME(NULL, &p, length)))
472
448
  ossl_raise(eASN1Error, NULL);
473
- ret = rb_protect((VALUE(*)_((VALUE)))asn1time_to_time,
449
+ ret = rb_protect((VALUE (*)(VALUE))asn1time_to_time,
474
450
  (VALUE)time, &status);
475
451
  ASN1_TIME_free(time);
476
452
  if(status) rb_jump_tag(status);
@@ -616,17 +592,14 @@ ossl_asn1_default_tag(VALUE obj)
616
592
  VALUE tmp_class, tag;
617
593
 
618
594
  tmp_class = CLASS_OF(obj);
619
- while (tmp_class) {
595
+ while (!NIL_P(tmp_class)) {
620
596
  tag = rb_hash_lookup(class_tag_map, tmp_class);
621
- if (tag != Qnil) {
622
- return NUM2INT(tag);
623
- }
624
- tmp_class = rb_class_superclass(tmp_class);
597
+ if (tag != Qnil)
598
+ return NUM2INT(tag);
599
+ tmp_class = rb_class_superclass(tmp_class);
625
600
  }
626
601
  ossl_raise(eASN1Error, "universal tag for %"PRIsVALUE" not found",
627
602
  rb_obj_class(obj));
628
-
629
- return -1; /* dummy */
630
603
  }
631
604
 
632
605
  static int
@@ -645,59 +618,45 @@ static int
645
618
  ossl_asn1_is_explicit(VALUE obj)
646
619
  {
647
620
  VALUE s;
648
- int ret = -1;
649
621
 
650
622
  s = ossl_asn1_get_tagging(obj);
651
- if(NIL_P(s)) return 0;
652
- else if(SYMBOL_P(s)){
653
- if (SYM2ID(s) == sIMPLICIT)
654
- ret = 0;
655
- else if (SYM2ID(s) == sEXPLICIT)
656
- ret = 1;
657
- }
658
- if(ret < 0){
623
+ if (NIL_P(s) || s == sym_IMPLICIT)
624
+ return 0;
625
+ else if (s == sym_EXPLICIT)
626
+ return 1;
627
+ else
659
628
  ossl_raise(eASN1Error, "invalid tag default");
660
- }
661
-
662
- return ret;
663
629
  }
664
630
 
665
631
  static int
666
632
  ossl_asn1_tag_class(VALUE obj)
667
633
  {
668
634
  VALUE s;
669
- int ret = -1;
670
635
 
671
636
  s = ossl_asn1_get_tag_class(obj);
672
- if(NIL_P(s)) ret = V_ASN1_UNIVERSAL;
673
- else if(SYMBOL_P(s)){
674
- if (SYM2ID(s) == sUNIVERSAL)
675
- ret = V_ASN1_UNIVERSAL;
676
- else if (SYM2ID(s) == sAPPLICATION)
677
- ret = V_ASN1_APPLICATION;
678
- else if (SYM2ID(s) == sCONTEXT_SPECIFIC)
679
- ret = V_ASN1_CONTEXT_SPECIFIC;
680
- else if (SYM2ID(s) == sPRIVATE)
681
- ret = V_ASN1_PRIVATE;
682
- }
683
- if(ret < 0){
637
+ if (NIL_P(s) || s == sym_UNIVERSAL)
638
+ return V_ASN1_UNIVERSAL;
639
+ else if (s == sym_APPLICATION)
640
+ return V_ASN1_APPLICATION;
641
+ else if (s == sym_CONTEXT_SPECIFIC)
642
+ return V_ASN1_CONTEXT_SPECIFIC;
643
+ else if (s == sym_PRIVATE)
644
+ return V_ASN1_PRIVATE;
645
+ else
684
646
  ossl_raise(eASN1Error, "invalid tag class");
685
- }
686
-
687
- return ret;
688
647
  }
689
648
 
690
649
  static VALUE
691
650
  ossl_asn1_class2sym(int tc)
692
651
  {
693
652
  if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
694
- return ID2SYM(sPRIVATE);
653
+ return sym_PRIVATE;
695
654
  else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
696
- return ID2SYM(sCONTEXT_SPECIFIC);
655
+ return sym_CONTEXT_SPECIFIC;
697
656
  else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
698
- return ID2SYM(sAPPLICATION);
657
+ return sym_APPLICATION;
699
658
  else
700
- return ID2SYM(sUNIVERSAL);
659
+ return sym_UNIVERSAL;
701
660
  }
702
661
 
703
662
  /*
@@ -721,7 +680,7 @@ ossl_asn1data_initialize(VALUE self, VALUE value, VALUE tag, VALUE tag_class)
721
680
  {
722
681
  if(!SYMBOL_P(tag_class))
723
682
  ossl_raise(eASN1Error, "invalid tag class");
724
- if((SYM2ID(tag_class) == sUNIVERSAL) && NUM2INT(tag) > 31)
683
+ if (tag_class == sym_UNIVERSAL && NUM2INT(tag) > 31)
725
684
  ossl_raise(eASN1Error, "tag number for Universal too large");
726
685
  ossl_asn1_set_tag(self, tag);
727
686
  ossl_asn1_set_value(self, value);
@@ -744,7 +703,7 @@ static VALUE
744
703
  join_der(VALUE enumerable)
745
704
  {
746
705
  VALUE str = rb_str_new(0, 0);
747
- rb_block_call(enumerable, rb_intern("each"), 0, 0, join_der_i, str);
706
+ rb_block_call(enumerable, id_each, 0, 0, join_der_i, str);
748
707
  return str;
749
708
  }
750
709
 
@@ -778,11 +737,11 @@ ossl_asn1data_to_der(VALUE self)
778
737
  if (inf_length == Qtrue) {
779
738
  is_cons = 2;
780
739
  }
781
- if((length = ossl_asn1_object_size(is_cons, RSTRING_LENINT(value), tag)) <= 0)
740
+ if((length = ASN1_object_size(is_cons, RSTRING_LENINT(value), tag)) <= 0)
782
741
  ossl_raise(eASN1Error, NULL);
783
742
  der = rb_str_new(0, length);
784
743
  p = (unsigned char *)RSTRING_PTR(der);
785
- ossl_asn1_put_object(&p, is_cons, RSTRING_LENINT(value), tag, tag_class);
744
+ ASN1_put_object(&p, is_cons, RSTRING_LENINT(value), tag, tag_class);
786
745
  memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
787
746
  p += RSTRING_LEN(value);
788
747
  ossl_str_adjust(der, p);
@@ -800,7 +759,7 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
800
759
 
801
760
  p = *pp;
802
761
 
803
- if(tc == sUNIVERSAL && tag < ossl_asn1_info_size) {
762
+ if(tc == sym_UNIVERSAL && tag < ossl_asn1_info_size) {
804
763
  switch(tag){
805
764
  case V_ASN1_EOC:
806
765
  value = decode_eoc(p, hlen+length);
@@ -842,13 +801,14 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
842
801
  *pp += hlen + length;
843
802
  *num_read = hlen + length;
844
803
 
845
- if (tc == sUNIVERSAL && tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass) {
804
+ if (tc == sym_UNIVERSAL &&
805
+ tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass) {
846
806
  VALUE klass = *ossl_asn1_info[tag].klass;
847
807
  VALUE args[4];
848
808
  args[0] = value;
849
809
  args[1] = INT2NUM(tag);
850
810
  args[2] = Qnil;
851
- args[3] = ID2SYM(tc);
811
+ args[3] = tc;
852
812
  asn1data = rb_obj_alloc(klass);
853
813
  ossl_asn1_initialize(4, args, asn1data);
854
814
  if(tag == V_ASN1_BIT_STRING){
@@ -857,7 +817,7 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
857
817
  }
858
818
  else {
859
819
  asn1data = rb_obj_alloc(cASN1Data);
860
- ossl_asn1data_initialize(asn1data, value, INT2NUM(tag), ID2SYM(tc));
820
+ ossl_asn1data_initialize(asn1data, value, INT2NUM(tag), tc);
861
821
  }
862
822
 
863
823
  return asn1data;
@@ -870,28 +830,27 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
870
830
  {
871
831
  VALUE value, asn1data, ary;
872
832
  int infinite;
873
- long off = *offset;
833
+ long available_len, off = *offset;
874
834
 
875
835
  infinite = (j == 0x21);
876
836
  ary = rb_ary_new();
877
837
 
878
- while (length > 0 || infinite) {
838
+ available_len = infinite ? max_len : length;
839
+ while (available_len > 0) {
879
840
  long inner_read = 0;
880
- value = ossl_asn1_decode0(pp, max_len, &off, depth + 1, yield, &inner_read);
841
+ value = ossl_asn1_decode0(pp, available_len, &off, depth + 1, yield, &inner_read);
881
842
  *num_read += inner_read;
882
- max_len -= inner_read;
843
+ available_len -= inner_read;
883
844
  rb_ary_push(ary, value);
884
- if (length > 0)
885
- length -= inner_read;
886
845
 
887
846
  if (infinite &&
888
847
  NUM2INT(ossl_asn1_get_tag(value)) == V_ASN1_EOC &&
889
- SYM2ID(ossl_asn1_get_tag_class(value)) == sUNIVERSAL) {
848
+ ossl_asn1_get_tag_class(value) == sym_UNIVERSAL) {
890
849
  break;
891
850
  }
892
851
  }
893
852
 
894
- if (tc == sUNIVERSAL) {
853
+ if (tc == sym_UNIVERSAL) {
895
854
  VALUE args[4];
896
855
  int not_sequence_or_set;
897
856
 
@@ -913,12 +872,12 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
913
872
  args[0] = ary;
914
873
  args[1] = INT2NUM(tag);
915
874
  args[2] = Qnil;
916
- args[3] = ID2SYM(tc);
875
+ args[3] = tc;
917
876
  ossl_asn1_initialize(4, args, asn1data);
918
877
  }
919
878
  else {
920
879
  asn1data = rb_obj_alloc(cASN1Data);
921
- ossl_asn1data_initialize(asn1data, ary, INT2NUM(tag), ID2SYM(tc));
880
+ ossl_asn1data_initialize(asn1data, ary, INT2NUM(tag), tc);
922
881
  }
923
882
 
924
883
  if (infinite)
@@ -948,13 +907,13 @@ ossl_asn1_decode0(unsigned char **pp, long length, long *offset, int depth,
948
907
  if(j & 0x80) ossl_raise(eASN1Error, NULL);
949
908
  if(len > length) ossl_raise(eASN1Error, "value is too short");
950
909
  if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
951
- tag_class = sPRIVATE;
910
+ tag_class = sym_PRIVATE;
952
911
  else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
953
- tag_class = sCONTEXT_SPECIFIC;
912
+ tag_class = sym_CONTEXT_SPECIFIC;
954
913
  else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
955
- tag_class = sAPPLICATION;
914
+ tag_class = sym_APPLICATION;
956
915
  else
957
- tag_class = sUNIVERSAL;
916
+ tag_class = sym_UNIVERSAL;
958
917
 
959
918
  hlen = p - start;
960
919
 
@@ -973,7 +932,7 @@ ossl_asn1_decode0(unsigned char **pp, long length, long *offset, int depth,
973
932
  if(j & V_ASN1_CONSTRUCTED) {
974
933
  *pp += hlen;
975
934
  off += hlen;
976
- asn1data = int_ossl_asn1_decode0_cons(pp, length, len, &off, depth, yield, j, tag, tag_class, &inner_read);
935
+ asn1data = int_ossl_asn1_decode0_cons(pp, length - hlen, len, &off, depth, yield, j, tag, tag_class, &inner_read);
977
936
  inner_read += hlen;
978
937
  }
979
938
  else {
@@ -1146,19 +1105,19 @@ ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
1146
1105
  ossl_raise(eASN1Error, "invalid tagging method");
1147
1106
  if(NIL_P(tag_class)) {
1148
1107
  if (NIL_P(tagging))
1149
- tag_class = ID2SYM(sUNIVERSAL);
1108
+ tag_class = sym_UNIVERSAL;
1150
1109
  else
1151
- tag_class = ID2SYM(sCONTEXT_SPECIFIC);
1110
+ tag_class = sym_CONTEXT_SPECIFIC;
1152
1111
  }
1153
1112
  if(!SYMBOL_P(tag_class))
1154
1113
  ossl_raise(eASN1Error, "invalid tag class");
1155
- if(!NIL_P(tagging) && SYM2ID(tagging) == sIMPLICIT && NUM2INT(tag) > 31)
1114
+ if (tagging == sym_IMPLICIT && NUM2INT(tag) > 31)
1156
1115
  ossl_raise(eASN1Error, "tag number for Universal too large");
1157
1116
  }
1158
1117
  else{
1159
1118
  tag = INT2NUM(ossl_asn1_default_tag(self));
1160
1119
  tagging = Qnil;
1161
- tag_class = ID2SYM(sUNIVERSAL);
1120
+ tag_class = sym_UNIVERSAL;
1162
1121
  }
1163
1122
  ossl_asn1_set_tag(self, tag);
1164
1123
  ossl_asn1_set_value(self, value);
@@ -1174,7 +1133,7 @@ ossl_asn1eoc_initialize(VALUE self) {
1174
1133
  VALUE tag, tagging, tag_class, value;
1175
1134
  tag = INT2NUM(ossl_asn1_default_tag(self));
1176
1135
  tagging = Qnil;
1177
- tag_class = ID2SYM(sUNIVERSAL);
1136
+ tag_class = sym_UNIVERSAL;
1178
1137
  value = rb_str_new("", 0);
1179
1138
  ossl_asn1_set_tag(self, tag);
1180
1139
  ossl_asn1_set_value(self, value);
@@ -1184,30 +1143,6 @@ ossl_asn1eoc_initialize(VALUE self) {
1184
1143
  return self;
1185
1144
  }
1186
1145
 
1187
- static int
1188
- ossl_i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp)
1189
- {
1190
- #if OPENSSL_VERSION_NUMBER < 0x00907000L
1191
- if(!a) return 0;
1192
- if(a->type == V_ASN1_BOOLEAN)
1193
- return i2d_ASN1_BOOLEAN(a->value.boolean, pp);
1194
- #endif
1195
- return i2d_ASN1_TYPE(a, pp);
1196
- }
1197
-
1198
- static void
1199
- ossl_ASN1_TYPE_free(ASN1_TYPE *a)
1200
- {
1201
- #if OPENSSL_VERSION_NUMBER < 0x00907000L
1202
- if(!a) return;
1203
- if(a->type == V_ASN1_BOOLEAN){
1204
- OPENSSL_free(a);
1205
- return;
1206
- }
1207
- #endif
1208
- ASN1_TYPE_free(a);
1209
- }
1210
-
1211
1146
  /*
1212
1147
  * call-seq:
1213
1148
  * asn1.to_der => DER-encoded String
@@ -1228,22 +1163,22 @@ ossl_asn1prim_to_der(VALUE self)
1228
1163
  explicit = ossl_asn1_is_explicit(self);
1229
1164
  asn1 = ossl_asn1_get_asn1type(self);
1230
1165
 
1231
- len = ossl_asn1_object_size(1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn);
1166
+ len = ASN1_object_size(1, i2d_ASN1_TYPE(asn1, NULL), tn);
1232
1167
  if(!(buf = OPENSSL_malloc(len))){
1233
- ossl_ASN1_TYPE_free(asn1);
1168
+ ASN1_TYPE_free(asn1);
1234
1169
  ossl_raise(eASN1Error, "cannot alloc buffer");
1235
1170
  }
1236
1171
  p = buf;
1237
1172
  if (tc == V_ASN1_UNIVERSAL) {
1238
- ossl_i2d_ASN1_TYPE(asn1, &p);
1173
+ i2d_ASN1_TYPE(asn1, &p);
1239
1174
  } else if (explicit) {
1240
- ossl_asn1_put_object(&p, 1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn, tc);
1241
- ossl_i2d_ASN1_TYPE(asn1, &p);
1175
+ ASN1_put_object(&p, 1, i2d_ASN1_TYPE(asn1, NULL), tn, tc);
1176
+ i2d_ASN1_TYPE(asn1, &p);
1242
1177
  } else {
1243
- ossl_i2d_ASN1_TYPE(asn1, &p);
1178
+ i2d_ASN1_TYPE(asn1, &p);
1244
1179
  *buf = tc | tn | (*buf & V_ASN1_CONSTRUCTED);
1245
1180
  }
1246
- ossl_ASN1_TYPE_free(asn1);
1181
+ ASN1_TYPE_free(asn1);
1247
1182
  reallen = p - buf;
1248
1183
  assert(reallen <= len);
1249
1184
  str = ossl_buf2str((char *)buf, rb_long2int(reallen)); /* buf will be free in ossl_buf2str */
@@ -1272,8 +1207,8 @@ ossl_asn1cons_to_der(VALUE self)
1272
1207
  if (inf_length == Qtrue) {
1273
1208
  VALUE ary, example;
1274
1209
  constructed = 2;
1275
- if (CLASS_OF(self) == cASN1Sequence ||
1276
- CLASS_OF(self) == cASN1Set) {
1210
+ if (rb_obj_class(self) == cASN1Sequence ||
1211
+ rb_obj_class(self) == cASN1Set) {
1277
1212
  tag = ossl_asn1_default_tag(self);
1278
1213
  }
1279
1214
  else { /* must be a constructive encoding of a primitive value */
@@ -1302,26 +1237,26 @@ ossl_asn1cons_to_der(VALUE self)
1302
1237
  }
1303
1238
  }
1304
1239
  else {
1305
- if (CLASS_OF(self) == cASN1Constructive)
1240
+ if (rb_obj_class(self) == cASN1Constructive)
1306
1241
  ossl_raise(eASN1Error, "Constructive shall only be used with infinite length");
1307
1242
  tag = ossl_asn1_default_tag(self);
1308
1243
  }
1309
1244
  explicit = ossl_asn1_is_explicit(self);
1310
1245
  value = join_der(ossl_asn1_get_value(self));
1311
1246
 
1312
- seq_len = ossl_asn1_object_size(constructed, RSTRING_LENINT(value), tag);
1313
- length = ossl_asn1_object_size(constructed, seq_len, tn);
1247
+ seq_len = ASN1_object_size(constructed, RSTRING_LENINT(value), tag);
1248
+ length = ASN1_object_size(constructed, seq_len, tn);
1314
1249
  str = rb_str_new(0, length);
1315
1250
  p = (unsigned char *)RSTRING_PTR(str);
1316
1251
  if(tc == V_ASN1_UNIVERSAL)
1317
- ossl_asn1_put_object(&p, constructed, RSTRING_LENINT(value), tn, tc);
1252
+ ASN1_put_object(&p, constructed, RSTRING_LENINT(value), tn, tc);
1318
1253
  else{
1319
1254
  if(explicit){
1320
- ossl_asn1_put_object(&p, constructed, seq_len, tn, tc);
1321
- ossl_asn1_put_object(&p, constructed, RSTRING_LENINT(value), tag, V_ASN1_UNIVERSAL);
1255
+ ASN1_put_object(&p, constructed, seq_len, tn, tc);
1256
+ ASN1_put_object(&p, constructed, RSTRING_LENINT(value), tag, V_ASN1_UNIVERSAL);
1322
1257
  }
1323
1258
  else{
1324
- ossl_asn1_put_object(&p, constructed, RSTRING_LENINT(value), tn, tc);
1259
+ ASN1_put_object(&p, constructed, RSTRING_LENINT(value), tn, tc);
1325
1260
  }
1326
1261
  }
1327
1262
  memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
@@ -1356,7 +1291,8 @@ ossl_asn1cons_to_der(VALUE self)
1356
1291
  static VALUE
1357
1292
  ossl_asn1cons_each(VALUE self)
1358
1293
  {
1359
- rb_ary_each(ossl_asn1_get_value(self));
1294
+ rb_block_call(ossl_asn1_get_value(self), id_each, 0, 0, 0, 0);
1295
+
1360
1296
  return self;
1361
1297
  }
1362
1298
 
@@ -1374,9 +1310,9 @@ ossl_asn1cons_each(VALUE self)
1374
1310
  static VALUE
1375
1311
  ossl_asn1obj_s_register(VALUE self, VALUE oid, VALUE sn, VALUE ln)
1376
1312
  {
1377
- StringValue(oid);
1378
- StringValue(sn);
1379
- StringValue(ln);
1313
+ StringValueCStr(oid);
1314
+ StringValueCStr(sn);
1315
+ StringValueCStr(ln);
1380
1316
 
1381
1317
  if(!OBJ_create(RSTRING_PTR(oid), RSTRING_PTR(sn), RSTRING_PTR(ln)))
1382
1318
  ossl_raise(eASN1Error, NULL);
@@ -1399,7 +1335,7 @@ ossl_asn1obj_get_sn(VALUE self)
1399
1335
  int nid;
1400
1336
 
1401
1337
  val = ossl_asn1_get_value(self);
1402
- if ((nid = OBJ_txt2nid(StringValuePtr(val))) != NID_undef)
1338
+ if ((nid = OBJ_txt2nid(StringValueCStr(val))) != NID_undef)
1403
1339
  ret = rb_str_new2(OBJ_nid2sn(nid));
1404
1340
 
1405
1341
  return ret;
@@ -1420,7 +1356,7 @@ ossl_asn1obj_get_ln(VALUE self)
1420
1356
  int nid;
1421
1357
 
1422
1358
  val = ossl_asn1_get_value(self);
1423
- if ((nid = OBJ_txt2nid(StringValuePtr(val))) != NID_undef)
1359
+ if ((nid = OBJ_txt2nid(StringValueCStr(val))) != NID_undef)
1424
1360
  ret = rb_str_new2(OBJ_nid2ln(nid));
1425
1361
 
1426
1362
  return ret;
@@ -1476,19 +1412,21 @@ OSSL_ASN1_IMPL_FACTORY_METHOD(EndOfContent)
1476
1412
  void
1477
1413
  Init_ossl_asn1(void)
1478
1414
  {
1415
+ #undef rb_intern
1479
1416
  VALUE ary;
1480
1417
  int i;
1481
1418
 
1482
1419
  #if 0
1483
- mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
1420
+ mOSSL = rb_define_module("OpenSSL");
1421
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
1484
1422
  #endif
1485
1423
 
1486
- sUNIVERSAL = rb_intern("UNIVERSAL");
1487
- sCONTEXT_SPECIFIC = rb_intern("CONTEXT_SPECIFIC");
1488
- sAPPLICATION = rb_intern("APPLICATION");
1489
- sPRIVATE = rb_intern("PRIVATE");
1490
- sEXPLICIT = rb_intern("EXPLICIT");
1491
- sIMPLICIT = rb_intern("IMPLICIT");
1424
+ sym_UNIVERSAL = ID2SYM(rb_intern_const("UNIVERSAL"));
1425
+ sym_CONTEXT_SPECIFIC = ID2SYM(rb_intern_const("CONTEXT_SPECIFIC"));
1426
+ sym_APPLICATION = ID2SYM(rb_intern_const("APPLICATION"));
1427
+ sym_PRIVATE = ID2SYM(rb_intern_const("PRIVATE"));
1428
+ sym_EXPLICIT = ID2SYM(rb_intern_const("EXPLICIT"));
1429
+ sym_IMPLICIT = ID2SYM(rb_intern_const("IMPLICIT"));
1492
1430
 
1493
1431
  sivVALUE = rb_intern("@value");
1494
1432
  sivTAG = rb_intern("@tag");
@@ -1781,12 +1719,12 @@ Init_ossl_asn1(void)
1781
1719
  * == Primitive sub-classes and their mapping to Ruby classes
1782
1720
  * * OpenSSL::ASN1::EndOfContent <=> +value+ is always +nil+
1783
1721
  * * OpenSSL::ASN1::Boolean <=> +value+ is a +Boolean+
1784
- * * OpenSSL::ASN1::Integer <=> +value+ is a +Number+
1722
+ * * OpenSSL::ASN1::Integer <=> +value+ is an OpenSSL::BN
1785
1723
  * * OpenSSL::ASN1::BitString <=> +value+ is a +String+
1786
1724
  * * OpenSSL::ASN1::OctetString <=> +value+ is a +String+
1787
1725
  * * OpenSSL::ASN1::Null <=> +value+ is always +nil+
1788
1726
  * * OpenSSL::ASN1::Object <=> +value+ is a +String+
1789
- * * OpenSSL::ASN1::Enumerated <=> +value+ is a +Number+
1727
+ * * OpenSSL::ASN1::Enumerated <=> +value+ is an OpenSSL::BN
1790
1728
  * * OpenSSL::ASN1::UTF8String <=> +value+ is a +String+
1791
1729
  * * OpenSSL::ASN1::NumericString <=> +value+ is a +String+
1792
1730
  * * OpenSSL::ASN1::PrintableString <=> +value+ is a +String+
@@ -1815,10 +1753,6 @@ Init_ossl_asn1(void)
1815
1753
  * it is not typically allocated this way, but rather that are received from
1816
1754
  * parsed ASN1 encodings.
1817
1755
  *
1818
- * While OpenSSL::ASN1::ObjectId.new will allocate a new ObjectId, it is
1819
- * not typically allocated this way, but rather that are received from
1820
- * parsed ASN1 encodings.
1821
- *
1822
1756
  * === Additional attributes
1823
1757
  * * +sn+: the short name as defined in <openssl/objects.h>.
1824
1758
  * * +ln+: the long name as defined in <openssl/objects.h>.
@@ -2000,4 +1934,6 @@ do{\
2000
1934
  rb_hash_aset(class_tag_map, cASN1UniversalString, INT2NUM(V_ASN1_UNIVERSALSTRING));
2001
1935
  rb_hash_aset(class_tag_map, cASN1BMPString, INT2NUM(V_ASN1_BMPSTRING));
2002
1936
  rb_global_variable(&class_tag_map);
1937
+
1938
+ id_each = rb_intern_const("each");
2003
1939
  }