类 OpenSSL::Provider
此类是访问 openssl 的 Provider
的入口。另请参见 www.openssl.org/docs/manmaster/man7/provider.html
公共类方法
OpenSSL::Provider.load(name) → provider 点击切换源代码
此方法加载并初始化一个提供程序。
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_names → [provider_name, ...] 点击切换源代码
返回一个包含当前已加载提供程序名称的数组。
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; }
公共实例方法
inspect → string 点击切换源代码
以美观的方式打印此提供程序。
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)); }
name → string 点击切换源代码
获取此提供程序的名称。
如果此提供程序已卸载,则会引发 OpenSSL::Provider::ProviderError
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)); }
unload → true 点击切换源代码
此方法卸载此提供程序。
如果提供程序卸载失败或已卸载,则会引发 OpenSSL::Provider::ProviderError
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; }