123456789_123456789_123456789_123456789_123456789_

Class: OpenSSL::Provider

Relationships & Source Files
Namespace Children
Exceptions:
Inherits: Object
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

Class Method Summary

Instance Method Summary

Class Method Details

.load(name) ⇒ Provider

This method loads and initializes a provider

[ GitHub ]

  
# 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;
}

.provider_namesProvider, ...

Returns an array of currently loaded provider names.

[ GitHub ]

  
# 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.

[ GitHub ]

  
# 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 Provider::ProviderError

[ GitHub ]

  
# 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 Provider::ProviderError

[ GitHub ]

  
# 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;
}