Class: OpenSSL::Provider

Inherits:
Object
  • Object
show all
Defined in:
ext/openssl/ossl_provider.c,
ext/openssl/ossl_provider.c

Overview

This class is the access to openssl’s Provider See also, www.openssl.org/docs/manmaster/man7/provider.html

Defined Under Namespace

Classes: ProviderError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.OpenSSL::Provider.load(name) ⇒ Object

This method loads and initializes a provider



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/openssl/ossl_provider.c', line 54

static VALUE
ossl_provider_s_load(VALUE klass, VALUE name)
{
    OSSL_PROVIDER *provider = NULL;
    VALUE obj;

    const char *provider_name_ptr = StringValueCStr(name);

    provider = OSSL_PROVIDER_load(NULL, provider_name_ptr);
    if (provider == NULL) {
        ossl_raise(eProviderError, "Failed to load %s provider", provider_name_ptr);
    }
    obj = NewProvider(klass);
    SetProvider(obj, provider);

    return obj;
}

.OpenSSL::Provider.provider_namesArray

Returns an array of currently loaded provider names.

Returns:

  • (Array)


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'ext/openssl/ossl_provider.c', line 104

static VALUE
ossl_provider_s_provider_names(VALUE klass)
{
    VALUE ary = rb_ary_new();
    struct ary_with_state cbdata = { ary, 0 };

    int result = OSSL_PROVIDER_do_all(NULL, &push_provider, (void*)&cbdata);
    if (result != 1 ) {
        if (cbdata.state) {
            rb_jump_tag(cbdata.state);
        } else {
            ossl_raise(eProviderError, "Failed to load provider names");
        }
    }

    return ary;
}

Instance Method Details

#inspectString

Pretty prints this provider.

Returns:

  • (String)


174
175
176
177
178
179
180
181
182
183
184
185
# File 'ext/openssl/ossl_provider.c', line 174

static VALUE
ossl_provider_inspect(VALUE self)
{
    OSSL_PROVIDER *prov;
    if (RTYPEDDATA_DATA(self) == NULL ) {
        return rb_sprintf("#<%"PRIsVALUE" unloaded provider>", rb_obj_class(self));
    }
    GetProvider(self, prov);

    return rb_sprintf("#<%"PRIsVALUE" name=\"%s\">",
                      rb_obj_class(self), OSSL_PROVIDER_get0_name(prov));
}

#nameString

Get the name of this provider.

if this provider is already unloaded, it raises OpenSSL::Provider::ProviderError

Returns:

  • (String)


156
157
158
159
160
161
162
163
164
165
166
# File 'ext/openssl/ossl_provider.c', line 156

static VALUE
ossl_provider_get_name(VALUE self)
{
    OSSL_PROVIDER *prov;
    if (RTYPEDDATA_DATA(self) == NULL) {
        ossl_raise(eProviderError, "Provider already unloaded.");
    }
    GetProvider(self, prov);

    return rb_str_new2(OSSL_PROVIDER_get0_name(prov));
}

#unloadtrue

This method unloads this provider.

if provider unload fails or already unloaded, it raises OpenSSL::Provider::ProviderError

Returns:

  • (true)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'ext/openssl/ossl_provider.c', line 130

static VALUE
ossl_provider_unload(VALUE self)
{
    OSSL_PROVIDER *prov;
    if (RTYPEDDATA_DATA(self) == NULL) {
        ossl_raise(eProviderError, "Provider already unloaded.");
    }
    GetProvider(self, prov);

    int result = OSSL_PROVIDER_unload(prov);

    if (result != 1) {
        ossl_raise(eProviderError, "Failed to unload provider");
    }
    RTYPEDDATA_DATA(self) = NULL;
    return Qtrue;
}