Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
ossl_bio.c
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' team members
3  * Copyright (C) 2003
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 BIO *
13 ossl_obj2bio(volatile VALUE *pobj)
14 {
15  VALUE obj = *pobj;
16  BIO *bio;
17 
18  if (RB_TYPE_P(obj, T_FILE))
19  obj = rb_funcallv(obj, rb_intern("read"), 0, NULL);
21  bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
22  if (!bio)
23  ossl_raise(eOSSLError, "BIO_new_mem_buf");
24  *pobj = obj;
25  return bio;
26 }
27 
28 VALUE
29 ossl_membio2str(BIO *bio)
30 {
31  VALUE ret;
32  int state;
33  BUF_MEM *buf;
34 
35  BIO_get_mem_ptr(bio, &buf);
36  ret = ossl_str_new(buf->data, buf->length, &state);
37  BIO_free(bio);
38  if (state)
39  rb_jump_tag(state);
40 
41  return ret;
42 }
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.1.h:5742
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
ossl_membio2str
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:29
VALUE
unsigned long VALUE
Definition: ruby.h:102
ossl_obj2bio
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
rb_intern
#define rb_intern(str)
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
RSTRING_LENINT
#define RSTRING_LENINT(str)
Definition: ruby.h:1017
ossl.h
NULL
#define NULL
Definition: _sdbm.c:101
T_FILE
#define T_FILE
Definition: ruby.h:534
rb_jump_tag
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
Definition: eval.c:884
ossl_raise
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:293
ossl_str_new
VALUE ossl_str_new(const char *ptr, long len, int *pstate)
Definition: ossl.c:101
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
StringValue
use StringValue() instead")))
eOSSLError
VALUE eOSSLError
Definition: ossl.c:236
rb_funcallv
#define rb_funcallv(recv, mid, argc, argv)
Definition: rb_mjit_min_header-2.7.1.h:7904