rubysl-openssl 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,9 @@ VALUE eSSLError;
29
29
  VALUE cSSLContext;
30
30
  VALUE cSSLSocket;
31
31
 
32
+ static VALUE eSSLErrorWaitReadable;
33
+ static VALUE eSSLErrorWaitWritable;
34
+
32
35
  #define ossl_sslctx_set_cert(o,v) rb_iv_set((o),"@cert",(v))
33
36
  #define ossl_sslctx_set_key(o,v) rb_iv_set((o),"@key",(v))
34
37
  #define ossl_sslctx_set_client_ca(o,v) rb_iv_set((o),"@client_ca",(v))
@@ -100,6 +103,8 @@ static const char *ossl_ssl_attrs[] = {
100
103
 
101
104
  ID ID_callback_state;
102
105
 
106
+ static VALUE sym_exception;
107
+
103
108
  /*
104
109
  * SSLContext class
105
110
  */
@@ -418,7 +423,7 @@ ossl_sslctx_session_new_cb(SSL *ssl, SSL_SESSION *sess)
418
423
  }
419
424
 
420
425
  /*
421
- * return 0 which means to OpenSSL that the the session is still
426
+ * return 0 which means to OpenSSL that the session is still
422
427
  * valid (since we created Ruby Session object) and was not freed by us
423
428
  * with SSL_SESSION_free(). Call SSLContext#remove_session(sess) in
424
429
  * session_get_cb block if you don't want OpenSSL to cache the session
@@ -472,7 +477,7 @@ ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
472
477
  }
473
478
 
474
479
  static VALUE
475
- ossl_sslctx_add_extra_chain_cert_i(VALUE i, VALUE arg)
480
+ ossl_sslctx_add_extra_chain_cert_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
476
481
  {
477
482
  X509 *x509;
478
483
  SSL_CTX *ctx;
@@ -713,7 +718,7 @@ ossl_sslctx_setup(VALUE self)
713
718
  if(!NIL_P(val)){
714
719
  if(TYPE(val) == T_ARRAY){
715
720
  for(i = 0; i < RARRAY_LEN(val); i++){
716
- client_ca = GetX509CertPtr(rb_ary_entry(val, i));
721
+ client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
717
722
  if (!SSL_CTX_add_client_CA(ctx, client_ca)){
718
723
  /* Copies X509_NAME => FREE it. */
719
724
  ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
@@ -1092,6 +1097,7 @@ ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
1092
1097
  /*
1093
1098
  * SSLSocket class
1094
1099
  */
1100
+ #ifndef OPENSSL_NO_SOCK
1095
1101
  static void
1096
1102
  ossl_ssl_shutdown(SSL *ssl)
1097
1103
  {
@@ -1105,7 +1111,7 @@ ossl_ssl_shutdown(SSL *ssl)
1105
1111
  * Ignore the case SSL_shutdown returns -1. Empty handshake_func
1106
1112
  * must not happen.
1107
1113
  */
1108
- if (rc = SSL_shutdown(ssl))
1114
+ if ((rc = SSL_shutdown(ssl)))
1109
1115
  break;
1110
1116
  }
1111
1117
  SSL_clear(ssl);
@@ -1131,7 +1137,7 @@ ossl_ssl_s_alloc(VALUE klass)
1131
1137
  * SSLSocket.new(io, ctx) => aSSLSocket
1132
1138
  *
1133
1139
  * Creates a new SSL socket from +io+ which must be a real ruby object (not an
1134
- * IO-like object that responds to read/write.
1140
+ * IO-like object that responds to read/write).
1135
1141
  *
1136
1142
  * If +ctx+ is provided the SSL Sockets initial params will be taken from
1137
1143
  * the context.
@@ -1229,8 +1235,7 @@ static void
1229
1235
  write_would_block(int nonblock)
1230
1236
  {
1231
1237
  if (nonblock) {
1232
- VALUE exc = ossl_exc_new(eSSLError, "write would block");
1233
- rb_extend_object(exc, rb_mWaitWritable);
1238
+ VALUE exc = ossl_exc_new(eSSLErrorWaitWritable, "write would block");
1234
1239
  rb_exc_raise(exc);
1235
1240
  }
1236
1241
  }
@@ -1239,8 +1244,7 @@ static void
1239
1244
  read_would_block(int nonblock)
1240
1245
  {
1241
1246
  if (nonblock) {
1242
- VALUE exc = ossl_exc_new(eSSLError, "read would block");
1243
- rb_extend_object(exc, rb_mWaitReadable);
1247
+ VALUE exc = ossl_exc_new(eSSLErrorWaitReadable, "read would block");
1244
1248
  rb_exc_raise(exc);
1245
1249
  }
1246
1250
  }
@@ -1371,10 +1375,16 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1371
1375
  {
1372
1376
  SSL *ssl;
1373
1377
  int ilen, nread = 0;
1378
+ int no_exception = 0;
1374
1379
  VALUE len, str;
1375
1380
  rb_io_t *fptr;
1381
+ VALUE opts = Qnil;
1382
+
1383
+ rb_scan_args(argc, argv, "11:", &len, &str, &opts);
1384
+
1385
+ if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
1386
+ no_exception = 1;
1376
1387
 
1377
- rb_scan_args(argc, argv, "11", &len, &str);
1378
1388
  ilen = NUM2INT(len);
1379
1389
  if(NIL_P(str)) str = rb_str_new(0, ilen);
1380
1390
  else{
@@ -1395,17 +1405,23 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1395
1405
  case SSL_ERROR_NONE:
1396
1406
  goto end;
1397
1407
  case SSL_ERROR_ZERO_RETURN:
1408
+ if (no_exception) { return Qnil; }
1398
1409
  rb_eof_error();
1399
1410
  case SSL_ERROR_WANT_WRITE:
1411
+ if (no_exception) { return ID2SYM(rb_intern("wait_writable")); }
1400
1412
  write_would_block(nonblock);
1401
1413
  rb_io_wait_writable(FPTR_TO_FD(fptr));
1402
1414
  continue;
1403
1415
  case SSL_ERROR_WANT_READ:
1416
+ if (no_exception) { return ID2SYM(rb_intern("wait_readable")); }
1404
1417
  read_would_block(nonblock);
1405
1418
  rb_io_wait_readable(FPTR_TO_FD(fptr));
1406
1419
  continue;
1407
1420
  case SSL_ERROR_SYSCALL:
1408
- if(ERR_peek_error() == 0 && nread == 0) rb_eof_error();
1421
+ if(ERR_peek_error() == 0 && nread == 0) {
1422
+ if (no_exception) { return Qnil; }
1423
+ rb_eof_error();
1424
+ }
1409
1425
  rb_sys_fail(0);
1410
1426
  default:
1411
1427
  ossl_raise(eSSLError, "SSL_read");
@@ -1443,9 +1459,11 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
1443
1459
  * call-seq:
1444
1460
  * ssl.sysread_nonblock(length) => string
1445
1461
  * ssl.sysread_nonblock(length, buffer) => buffer
1462
+ * ssl.sysread_nonblock(length[, buffer [, opts]) => buffer
1446
1463
  *
1447
1464
  * A non-blocking version of #sysread. Raises an SSLError if reading would
1448
- * block.
1465
+ * block. If "exception: false" is passed, this method returns a symbol of
1466
+ * :wait_readable, :wait_writable, or nil, rather than raising an exception.
1449
1467
  *
1450
1468
  * Reads +length+ bytes from the SSL connection. If a pre-allocated +buffer+
1451
1469
  * is provided the data will be written into it.
@@ -1457,7 +1475,7 @@ ossl_ssl_read_nonblock(int argc, VALUE *argv, VALUE self)
1457
1475
  }
1458
1476
 
1459
1477
  static VALUE
1460
- ossl_ssl_write_internal(VALUE self, VALUE str, int nonblock)
1478
+ ossl_ssl_write_internal(VALUE self, VALUE str, int nonblock, int no_exception)
1461
1479
  {
1462
1480
  SSL *ssl;
1463
1481
  int nwrite = 0;
@@ -1474,10 +1492,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, int nonblock)
1474
1492
  case SSL_ERROR_NONE:
1475
1493
  goto end;
1476
1494
  case SSL_ERROR_WANT_WRITE:
1495
+ if (no_exception) { return ID2SYM(rb_intern("wait_writable")); }
1477
1496
  write_would_block(nonblock);
1478
1497
  rb_io_wait_writable(FPTR_TO_FD(fptr));
1479
1498
  continue;
1480
1499
  case SSL_ERROR_WANT_READ:
1500
+ if (no_exception) { return ID2SYM(rb_intern("wait_readable")); }
1481
1501
  read_would_block(nonblock);
1482
1502
  rb_io_wait_readable(FPTR_TO_FD(fptr));
1483
1503
  continue;
@@ -1507,7 +1527,7 @@ ossl_ssl_write_internal(VALUE self, VALUE str, int nonblock)
1507
1527
  static VALUE
1508
1528
  ossl_ssl_write(VALUE self, VALUE str)
1509
1529
  {
1510
- return ossl_ssl_write_internal(self, str, 0);
1530
+ return ossl_ssl_write_internal(self, str, 0, 0);
1511
1531
  }
1512
1532
 
1513
1533
  /*
@@ -1518,9 +1538,18 @@ ossl_ssl_write(VALUE self, VALUE str)
1518
1538
  * SSLError if writing would block.
1519
1539
  */
1520
1540
  static VALUE
1521
- ossl_ssl_write_nonblock(VALUE self, VALUE str)
1541
+ ossl_ssl_write_nonblock(int argc, VALUE *argv, VALUE self)
1522
1542
  {
1523
- return ossl_ssl_write_internal(self, str, 1);
1543
+ VALUE str;
1544
+ VALUE opts = Qnil;
1545
+ int no_exception = 0;
1546
+
1547
+ rb_scan_args(argc, argv, "1:", &str, &opts);
1548
+
1549
+ if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
1550
+ no_exception = 1;
1551
+
1552
+ return ossl_ssl_write_internal(self, str, 1, no_exception);
1524
1553
  }
1525
1554
 
1526
1555
  /*
@@ -1633,7 +1662,7 @@ ossl_ssl_get_peer_cert_chain(VALUE self)
1633
1662
 
1634
1663
  /*
1635
1664
  * call-seq:
1636
- * ssl.version => String
1665
+ * ssl.ssl_version => String
1637
1666
  *
1638
1667
  * Returns a String representing the SSL/TLS version that was negotiated
1639
1668
  * for the connection, for example "TLSv1.2".
@@ -1794,7 +1823,7 @@ ossl_ssl_get_client_ca_list(VALUE self)
1794
1823
  return ossl_x509name_sk2ary(ca);
1795
1824
  }
1796
1825
 
1797
- #ifdef HAVE_OPENSSL_NPN_NEGOTIATED
1826
+ # ifdef HAVE_OPENSSL_NPN_NEGOTIATED
1798
1827
  /*
1799
1828
  * call-seq:
1800
1829
  * ssl.npn_protocol => String
@@ -1817,7 +1846,8 @@ ossl_ssl_npn_protocol(VALUE self)
1817
1846
  else
1818
1847
  return rb_str_new((const char *) out, outlen);
1819
1848
  }
1820
- #endif
1849
+ # endif
1850
+ #endif /* !defined(OPENSSL_NO_SOCK) */
1821
1851
 
1822
1852
  void
1823
1853
  Init_ossl_ssl()
@@ -1852,6 +1882,10 @@ Init_ossl_ssl()
1852
1882
  * Generic error class raised by SSLSocket and SSLContext.
1853
1883
  */
1854
1884
  eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError);
1885
+ eSSLErrorWaitReadable = rb_define_class_under(mSSL, "SSLErrorWaitReadable", eSSLError);
1886
+ rb_include_module(eSSLErrorWaitReadable, rb_mWaitReadable);
1887
+ eSSLErrorWaitWritable = rb_define_class_under(mSSL, "SSLErrorWaitWritable", eSSLError);
1888
+ rb_include_module(eSSLErrorWaitWritable, rb_mWaitWritable);
1855
1889
 
1856
1890
  Init_ossl_ssl_session();
1857
1891
 
@@ -1970,7 +2004,7 @@ Init_ossl_ssl()
1970
2004
 
1971
2005
  /*
1972
2006
  * Sets the context in which a session can be reused. This allows
1973
- * sessions for multiple applications to be distinguished, for exapmle, by
2007
+ * sessions for multiple applications to be distinguished, for example, by
1974
2008
  * name.
1975
2009
  */
1976
2010
  rb_attr(cSSLContext, rb_intern("session_id_context"), 1, 1, Qfalse);
@@ -2144,6 +2178,9 @@ Init_ossl_ssl()
2144
2178
  *
2145
2179
  */
2146
2180
  cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
2181
+ #ifdef OPENSSL_NO_SOCK
2182
+ rb_define_method(cSSLSocket, "initialize", rb_notimplement, -1);
2183
+ #else
2147
2184
  rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
2148
2185
  for(i = 0; i < numberof(ossl_ssl_attr_readers); i++)
2149
2186
  rb_attr(cSSLSocket, rb_intern(ossl_ssl_attr_readers[i]), 1, 0, Qfalse);
@@ -2158,7 +2195,7 @@ Init_ossl_ssl()
2158
2195
  rb_define_method(cSSLSocket, "sysread", ossl_ssl_read, -1);
2159
2196
  rb_define_private_method(cSSLSocket, "sysread_nonblock", ossl_ssl_read_nonblock, -1);
2160
2197
  rb_define_method(cSSLSocket, "syswrite", ossl_ssl_write, 1);
2161
- rb_define_private_method(cSSLSocket, "syswrite_nonblock", ossl_ssl_write_nonblock, 1);
2198
+ rb_define_private_method(cSSLSocket, "syswrite_nonblock", ossl_ssl_write_nonblock, -1);
2162
2199
  rb_define_method(cSSLSocket, "sysclose", ossl_ssl_close, 0);
2163
2200
  rb_define_method(cSSLSocket, "cert", ossl_ssl_get_cert, 0);
2164
2201
  rb_define_method(cSSLSocket, "peer_cert", ossl_ssl_get_peer_cert, 0);
@@ -2172,8 +2209,9 @@ Init_ossl_ssl()
2172
2209
  rb_define_method(cSSLSocket, "session=", ossl_ssl_set_session, 1);
2173
2210
  rb_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0);
2174
2211
  rb_define_method(cSSLSocket, "client_ca", ossl_ssl_get_client_ca_list, 0);
2175
- #ifdef HAVE_OPENSSL_NPN_NEGOTIATED
2212
+ # ifdef HAVE_OPENSSL_NPN_NEGOTIATED
2176
2213
  rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
2214
+ # endif
2177
2215
  #endif
2178
2216
 
2179
2217
  #define ossl_ssl_def_const(x) rb_define_const(mSSL, #x, INT2NUM(SSL_##x))
@@ -2230,4 +2268,6 @@ Init_ossl_ssl()
2230
2268
  ossl_ssl_def_const(OP_PKCS1_CHECK_2);
2231
2269
  ossl_ssl_def_const(OP_NETSCAPE_CA_DN_BUG);
2232
2270
  ossl_ssl_def_const(OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
2271
+
2272
+ sym_exception = ID2SYM(rb_intern("exception"));
2233
2273
  }
@@ -165,8 +165,8 @@ ossl_x509attr_get_oid(VALUE self)
165
165
  # define OSSL_X509ATTR_IS_SINGLE(attr) ((attr)->single)
166
166
  # define OSSL_X509ATTR_SET_SINGLE(attr) ((attr)->single = 1)
167
167
  #else
168
- # define OSSL_X509ATTR_IS_SINGLE(attr) (!(attr)->set)
169
- # define OSSL_X509ATTR_SET_SINGLE(attr) ((attr)->set = 0)
168
+ # define OSSL_X509ATTR_IS_SINGLE(attr) (!(attr)->value.set)
169
+ # define OSSL_X509ATTR_SET_SINGLE(attr) ((attr)->value.set = 0)
170
170
  #endif
171
171
 
172
172
  /*
@@ -66,7 +66,7 @@ ossl_x509_new_from_file(VALUE filename)
66
66
  if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
67
67
  ossl_raise(eX509CertError, "%s", strerror(errno));
68
68
  }
69
- rb_update_max_fd(fileno(fp));
69
+ rb_fd_fix_cloexec(fileno(fp));
70
70
  x509 = PEM_read_X509(fp, NULL, NULL, NULL);
71
71
  /*
72
72
  * prepare for DER...
@@ -651,13 +651,13 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
651
651
  Check_Type(ary, T_ARRAY);
652
652
  /* All ary's members should be X509Extension */
653
653
  for (i=0; i<RARRAY_LEN(ary); i++) {
654
- OSSL_Check_Kind(rb_ary_entry(ary, i), cX509Ext);
654
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
655
655
  }
656
656
  GetX509(self, x509);
657
657
  sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
658
658
  x509->cert_info->extensions = NULL;
659
659
  for (i=0; i<RARRAY_LEN(ary); i++) {
660
- ext = DupX509ExtPtr(rb_ary_entry(ary, i));
660
+ ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
661
661
 
662
662
  if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
663
663
  X509_EXTENSION_free(ext);
@@ -290,13 +290,13 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
290
290
  Check_Type(ary, T_ARRAY);
291
291
  /* All ary members should be X509 Revoked */
292
292
  for (i=0; i<RARRAY_LEN(ary); i++) {
293
- OSSL_Check_Kind(rb_ary_entry(ary, i), cX509Rev);
293
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Rev);
294
294
  }
295
295
  GetX509CRL(self, crl);
296
296
  sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
297
297
  crl->crl->revoked = NULL;
298
298
  for (i=0; i<RARRAY_LEN(ary); i++) {
299
- rev = DupX509RevokedPtr(rb_ary_entry(ary, i));
299
+ rev = DupX509RevokedPtr(RARRAY_PTR(ary)[i]);
300
300
  if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
301
301
  ossl_raise(eX509CRLError, NULL);
302
302
  }
@@ -464,13 +464,13 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
464
464
  Check_Type(ary, T_ARRAY);
465
465
  /* All ary members should be X509 Extensions */
466
466
  for (i=0; i<RARRAY_LEN(ary); i++) {
467
- OSSL_Check_Kind(rb_ary_entry(ary, i), cX509Ext);
467
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
468
468
  }
469
469
  GetX509CRL(self, crl);
470
470
  sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
471
471
  crl->crl->extensions = NULL;
472
472
  for (i=0; i<RARRAY_LEN(ary); i++) {
473
- ext = DupX509ExtPtr(rb_ary_entry(ary, i));
473
+ ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
474
474
  if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
475
475
  X509_EXTENSION_free(ext);
476
476
  ossl_raise(eX509CRLError, NULL);
@@ -92,7 +92,7 @@ static VALUE ossl_x509name_add_entry(int, VALUE*, VALUE);
92
92
  #define rb_aref(obj, key) rb_funcall((obj), id_aref, 1, (key))
93
93
 
94
94
  static VALUE
95
- ossl_x509name_init_i(VALUE i, VALUE args)
95
+ ossl_x509name_init_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
96
96
  {
97
97
  VALUE self = rb_ary_entry(args, 0);
98
98
  VALUE template = rb_ary_entry(args, 1);
@@ -406,13 +406,13 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
406
406
 
407
407
  Check_Type(ary, T_ARRAY);
408
408
  for (i=0;i<RARRAY_LEN(ary); i++) {
409
- OSSL_Check_Kind(rb_ary_entry(ary, i), cX509Attr);
409
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Attr);
410
410
  }
411
411
  GetX509Req(self, req);
412
412
  sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free);
413
413
  req->req_info->attributes = NULL;
414
414
  for (i=0;i<RARRAY_LEN(ary); i++) {
415
- item = rb_ary_entry(ary, i);
415
+ item = RARRAY_PTR(ary)[i];
416
416
  attr = DupX509AttrPtr(item);
417
417
  if (!X509_REQ_add1_attr(req, attr)) {
418
418
  ossl_raise(eX509ReqError, NULL);
@@ -176,13 +176,13 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
176
176
 
177
177
  Check_Type(ary, T_ARRAY);
178
178
  for (i=0; i<RARRAY_LEN(ary); i++) {
179
- OSSL_Check_Kind(rb_ary_entry(ary, i), cX509Ext);
179
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
180
180
  }
181
181
  GetX509Rev(self, rev);
182
182
  sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
183
183
  rev->extensions = NULL;
184
184
  for (i=0; i<RARRAY_LEN(ary); i++) {
185
- item = rb_ary_entry(ary, i);
185
+ item = RARRAY_PTR(ary)[i];
186
186
  ext = DupX509ExtPtr(item);
187
187
  if(!X509_REVOKED_add_ext(rev, ext, -1)) {
188
188
  ossl_raise(eX509RevError, NULL);
@@ -135,9 +135,9 @@ ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
135
135
  ossl_x509store_set_vfy_cb(self, Qnil);
136
136
 
137
137
  #if (OPENSSL_VERSION_NUMBER < 0x00907000L)
138
- rb_iv_set(self, "@flags", INT2NUM(0));
139
- rb_iv_set(self, "@purpose", INT2NUM(0));
140
- rb_iv_set(self, "@trust", INT2NUM(0));
138
+ rb_iv_set(self, "@flags", INT2FIX(0));
139
+ rb_iv_set(self, "@purpose", INT2FIX(0));
140
+ rb_iv_set(self, "@trust", INT2FIX(0));
141
141
  #endif
142
142
 
143
143
  /* last verification status */
@@ -257,7 +257,7 @@ ossl_x509store_add_path(VALUE self, VALUE dir)
257
257
 
258
258
  /*
259
259
  * call-seq:
260
- * store.set_default_path
260
+ * store.set_default_paths
261
261
  *
262
262
  * Adds the default certificates to the certificate store. These certificates
263
263
  * are loaded from the default configuration directory which can usually be
data/lib/openssl/bn.rb CHANGED
@@ -28,8 +28,11 @@ end # OpenSSL
28
28
  # Add double dispatch to Integer
29
29
  #
30
30
  class Integer
31
+ # Casts an Integer as an OpenSSL::BN
32
+ #
33
+ # See `man bn` for more info.
31
34
  def to_bn
32
- OpenSSL::BN::new(self.to_s(16), 16)
35
+ OpenSSL::BN::new(self)
33
36
  end
34
37
  end # Integer
35
38
 
@@ -1,23 +1,27 @@
1
- =begin
2
- = $RCSfile$ -- Buffering mix-in module.
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
1
+ # coding: binary
2
+ #--
3
+ #= $RCSfile$ -- Buffering mix-in module.
4
+ #
5
+ #= Info
6
+ # 'OpenSSL for Ruby 2' project
7
+ # Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
8
+ # All rights reserved.
9
+ #
10
+ #= Licence
11
+ # This program is licenced under the same licence as Ruby.
12
+ # (See the file 'LICENCE'.)
13
+ #
14
+ #= Version
15
+ # $Id$
16
+ #++
16
17
 
17
18
  ##
18
19
  # OpenSSL IO buffering mix-in module.
19
20
  #
20
21
  # This module allows an OpenSSL::SSL::SSLSocket to behave like an IO.
22
+ #
23
+ # You typically won't use this module directly, you can see it implemented in
24
+ # OpenSSL::SSL::SSLSocket.
21
25
 
22
26
  module OpenSSL::Buffering
23
27
  include Enumerable
@@ -34,7 +38,11 @@ module OpenSSL::Buffering
34
38
 
35
39
  BLOCK_SIZE = 1024*16
36
40
 
37
- def initialize(*args)
41
+ ##
42
+ # Creates an instance of OpenSSL's buffering IO module.
43
+
44
+ def initialize(*)
45
+ super
38
46
  @eof = false
39
47
  @rbuffer = ""
40
48
  @sync = @io.sync
@@ -161,7 +169,7 @@ module OpenSSL::Buffering
161
169
  # when the peer requests a new TLS/SSL handshake. See openssl the FAQ for
162
170
  # more details. http://www.openssl.org/support/faq.html
163
171
 
164
- def read_nonblock(maxlen, buf=nil)
172
+ def read_nonblock(maxlen, buf=nil, exception: true)
165
173
  if maxlen == 0
166
174
  if buf
167
175
  buf.clear
@@ -171,7 +179,7 @@ module OpenSSL::Buffering
171
179
  end
172
180
  end
173
181
  if @rbuffer.empty?
174
- return sysread_nonblock(maxlen, buf)
182
+ return sysread_nonblock(maxlen, buf, exception: exception)
175
183
  end
176
184
  ret = consume_rbuff(maxlen)
177
185
  if buf
@@ -370,9 +378,9 @@ module OpenSSL::Buffering
370
378
  # is when the peer requests a new TLS/SSL handshake. See the openssl FAQ
371
379
  # for more details. http://www.openssl.org/support/faq.html
372
380
 
373
- def write_nonblock(s)
381
+ def write_nonblock(s, exception: true)
374
382
  flush
375
- syswrite_nonblock(s)
383
+ syswrite_nonblock(s, exception: exception)
376
384
  end
377
385
 
378
386
  ##
@@ -58,7 +58,7 @@ module OpenSSL
58
58
  end
59
59
 
60
60
  # This class is only provided for backwards compatibility. Use OpenSSL::Cipher in the future.
61
- class Cipher < ::OpenSSL::Cipher
61
+ class Cipher < Cipher
62
62
  # add warning
63
63
  end
64
64
  end # Cipher