Method: OpenSSL::SSL::Session#initialize

Defined in:
ext/openssl/ossl_ssl_session.c

#new(ssl_socket) ⇒ Session #new(string) ⇒ Session

Creates a new Session object from an instance of SSLSocket or DER/PEM encoded String.

Overloads:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'ext/openssl/ossl_ssl_session.c', line 37

static VALUE
ossl_ssl_session_initialize(VALUE self, VALUE arg1)
{
    SSL_SESSION *ctx;

    if (RTYPEDDATA_DATA(self))
        ossl_raise(eSSLSession, "SSL Session already initialized");

    if (rb_obj_is_instance_of(arg1, cSSLSocket)) {
        SSL *ssl;

        GetSSL(arg1, ssl);

        if ((ctx = SSL_get1_session(ssl)) == NULL)
            ossl_raise(eSSLSession, "no session available");
    }
    else {
        BIO *in = ossl_obj2bio(&arg1);

        ctx = d2i_SSL_SESSION_bio(in, NULL);
        if (!ctx) {
            OSSL_BIO_reset(in);
            ctx = PEM_read_bio_SSL_SESSION(in, NULL, NULL, NULL);
        }
        BIO_free(in);
        if (!ctx)
            ossl_raise(rb_eArgError, "unknown type");
    }

    RTYPEDDATA_DATA(self) = ctx;

    return self;
}