Establishes _proc_ as the handler for tracing, or disables tracing if the parameter is +nil+. *Note:* this method is obsolete, please use TracePoint instead. _proc_ takes up to six parameters: * an event name * a filename * a line number * an object id * a binding * the name of a class _proc_ is invoked whenever an event occurs. Events are: +c-call+:: call a C-language routine +c-return+:: return from a C-language routine +call+:: call a Ruby method +class+:: start a class or module definition +end+:: finish a class or module definition +line+:: execute code on a new line +raise+:: raise an exception +return+:: return from a Ruby method Tracing is disabled within the context of _proc_. class Test def test a = 1 b = 2 end end set_trace_func proc { |event, file, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname } t = Test.new t.test line prog.rb:11 false c-call prog.rb:11 new Class c-call prog.rb:11 initialize Object c-return prog.rb:11 initialize Object c-return prog.rb:11 new Class line prog.rb:12 false call prog.rb:2 test Test line prog.rb:3 test Test line prog.rb:4 test Test return prog.rb:4 test Test
Note that for c-call
and c-return
events, the binding returned is the binding of the nearest Ruby method calling the C method, since C methods themselves do not have bindings.
Returns the last win32 Error
of the current executing Thread
or nil if none
Sets the last win32 Error
of the current executing Thread
to error
Starts tracing object allocations from the ObjectSpace
extension module.
For example:
require 'objspace' class C include ObjectSpace def foo trace_object_allocations do obj = Object.new p "#{allocation_sourcefile(obj)}:#{allocation_sourceline(obj)}" end end end C.new.foo #=> "objtrace.rb:8"
This example has included the ObjectSpace
module to make it easier to read, but you can also use the ::trace_object_allocations
notation (recommended).
Note that this feature introduces a huge performance decrease and huge memory consumption.
Calls CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON). Starts tracking memory allocations. See also OpenSSL.print_mem_leaks
.
This is available only when built with a capable OpenSSL
and –enable-debug configure option.
Clear default gem related variables. It is for test
Default options for gem commands for Ruby packagers.
The options here should be structured as an array of string “gem” command names as keys and a string of the default options as values.
Example:
def self.operating_system_defaults
{ 'install' => '--no-rdoc --no-ri --env-shebang', 'update' => '--no-rdoc --no-ri --env-shebang' }
end
Generates a private and public key unless a private key already exists. If this DH
instance was generated from public DH parameters (e.g. by encoding the result of DH#public_key
), then this method needs to be called first in order to generate the per-session keys before performing the actual key exchange.
Deprecated in version 3.0. This method is incompatible with OpenSSL
3.0.0 or later.
See also OpenSSL::PKey.generate_key
.
Example:
# DEPRECATED USAGE: This will not work on OpenSSL 3.0 or later dh0 = OpenSSL::PKey::DH.new(2048) dh = dh0.public_key # #public_key only copies the DH parameters (contrary to the name) dh.generate_key! puts dh.private? # => true puts dh0.pub_key == dh.pub_key #=> false # With OpenSSL::PKey.generate_key dh0 = OpenSSL::PKey::DH.new(2048) dh = OpenSSL::PKey.generate_key(dh0) puts dh0.pub_key == dh.pub_key #=> false
Generates a new random private and public key.
See also the OpenSSL
documentation for EC_KEY_generate_key()
ec = OpenSSL::PKey::EC.new("prime256v1") p ec.private_key # => nil ec.generate_key! p ec.private_key # => #<OpenSSL::BN XXXXXX>
Generates a new random private and public key.
See also the OpenSSL
documentation for EC_KEY_generate_key()
ec = OpenSSL::PKey::EC.new("prime256v1") p ec.private_key # => nil ec.generate_key! p ec.private_key # => #<OpenSSL::BN XXXXXX>
Parses the UTF-8 string representation of a distinguished name, according to RFC 2253.
See also to_utf8
for the opposite operation.
Parses the string representation of a distinguished name. Two different forms are supported:
OpenSSL format (X509_NAME_oneline()
) used by #to_s
. For example: /DC=com/DC=example/CN=nobody
OpenSSL format (X509_NAME_print()
) used by #to_s(OpenSSL::X509::Name::COMPAT)
. For example: DC=com, DC=example, CN=nobody
Neither of them is standardized and has quirks and inconsistencies in handling of escaped characters or multi-valued RDNs.
Use of this method is discouraged in new applications. See Name.parse_rfc2253
and to_utf8
for the alternative.
Returns the human readable error string corresponding to the error code retrieved by error
.
See also the man page X509_verify_cert_error_string(3).
Returns the depth of the chain. This is used in combination with error
.
See also the man page X509_STORE_CTX_get_error_depth(3).
Returns the certificate which caused the error.
See also the man page X509_STORE_CTX_get_current_cert(3).
Returns the CRL
which caused the error.
See also the man page X509_STORE_CTX_get_current_crl(3).
Signs data
using a private key pkey
. Unlike sign
, data
will not be hashed by digest
automatically.
See verify_raw
for the verification operation.
Added in version 3.0. See also the man page EVP_PKEY_sign(3).
digest
A String
that represents the message digest algorithm name, or nil
if the PKey
type requires no digest algorithm. Although this method will not hash data
with it, this parameter may still be required depending on the signature algorithm.
data
A String
. The data to be signed.
options
A Hash
that contains algorithm specific control operations to OpenSSL. See OpenSSL’s man page EVP_PKEY_CTX_ctrl_str(3) for details.
Example:
data = "Sign me!" hash = OpenSSL::Digest.digest("SHA256", data) pkey = OpenSSL::PKey.generate_key("RSA", rsa_keygen_bits: 2048) signopts = { rsa_padding_mode: "pss" } signature = pkey.sign_raw("SHA256", hash, signopts) # Creates a copy of the RSA key pkey, but without the private components pub_key = pkey.public_key puts pub_key.verify_raw("SHA256", signature, hash, signopts) # => true
Verifies the signature
for the data
using a public key pkey
. Unlike verify
, this method will not hash data
with digest
automatically.
Returns true
if the signature is successfully verified, false
otherwise. The caller must check the return value.
See sign_raw
for the signing operation and an example code.
Added in version 3.0. See also the man page EVP_PKEY_verify(3).
signature
A String
containing the signature to be verified.