Returns the destination encoding as an encoding object.
Returns the corresponding ASCII compatible encoding.
Returns nil if the argument is an ASCII compatible encoding.
“corresponding ASCII compatible encoding” is an ASCII compatible encoding which can represents exactly the same characters as the given ASCII incompatible encoding. So, no conversion undefined error occurs when converting between the two encodings.
Encoding::Converter.asciicompat_encoding("ISO-2022-JP") #=> #<Encoding:stateless-ISO-2022-JP> Encoding::Converter.asciicompat_encoding("UTF-16BE") #=> #<Encoding:UTF-8> Encoding::Converter.asciicompat_encoding("UTF-8") #=> nil
Returns the destination encoding as an Encoding
object.
Iterates over keys and values. Note that unlike other collections, each
without block isn’t supported.
Iterates over keys. Note that unlike other collections, each_key
without block isn’t supported.
Iterates over values. Note that unlike other collections, each_value
without block isn’t supported.
Format a Time
object as a String
using the format specified by RFC 1123.
CGI.rfc1123_date(Time.now) # Sat, 01 Jan 2000 00:00:00 GMT
Parses a C prototype signature
If Hash
tymap
is provided, the return value and the arguments from the signature
are expected to be keys, and the value will be the C type to be looked up.
Example:
require 'fiddle/import' include Fiddle::CParser #=> Object parse_signature('double sum(double, double)') #=> ["sum", Fiddle::TYPE_DOUBLE, [Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]] parse_signature('void update(void (*cb)(int code))') #=> ["update", Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP]] parse_signature('char (*getbuffer(void))[80]') #=> ["getbuffer", Fiddle::TYPE_VOIDP, []]
Creates a class to wrap the C struct with the value ty
See also Fiddle::Importer.struct
Calls the given block once for each byte in the stream.
OpenSSL::PKCS5.pbkdf2_hmac
has been renamed to OpenSSL::KDF.pbkdf2_hmac
. This method is provided for backwards compatibility.
Generates new parameters for the algorithm. algo_name is a String
that represents the algorithm. The optional argument options is a Hash
that specifies the options specific to the algorithm. The order of the options can be important.
A block can be passed optionally. The meaning of the arguments passed to the block varies depending on the implementation of the algorithm. The block may be called once or multiple times, or may not even be called.
For the supported options, see the documentation for the ‘openssl genpkey’ utility command.
pkey = OpenSSL::PKey.generate_parameters("DSA", "dsa_paramgen_bits" => 2048) p pkey.p.num_bits #=> 2048
Generates a new key (pair).
If a String
is given as the first argument, it generates a new random key for the algorithm specified by the name just as ::generate_parameters
does. If an OpenSSL::PKey::PKey
is given instead, it generates a new random key for the same algorithm as the key, using the parameters the key contains.
See ::generate_parameters
for the details of options and the given block.
pkey_params = OpenSSL::PKey.generate_parameters("DSA", "dsa_paramgen_bits" => 2048) pkey_params.priv_key #=> nil pkey = OpenSSL::PKey.generate_key(pkey_params) pkey.priv_key #=> #<OpenSSL::BN 6277...
PKCS #5 PBKDF2 (Password-Based Key Derivation Function 2) in combination with HMAC
. Takes pass, salt and iterations, and then derives a key of length bytes.
For more information about PBKDF2, see RFC 2898 Section 5.2 (www.rfc-editor.org/rfc/rfc2898#section-5.2).
The password.
The salt. Salts prevent attacks based on dictionaries of common passwords and attacks based on rainbow tables. It is a public value that can be safely stored along with the password (e.g. if the derived value is used for password storage).
The iteration count. This provides the ability to tune the algorithm. It is better to use the highest count possible for the maximum resistance to brute-force attacks.
The desired length of the derived key in octets.
The hash algorithm used with HMAC
for the PRF. May be a String
representing the algorithm name, or an instance of OpenSSL::Digest
.
Generate a sequence of checkbox elements, as a String
.
The checkboxes will all have the same name
attribute. Each checkbox is followed by a label. There will be one checkbox for each value. Each value can be specified as a String
, which will be used both as the value of the VALUE attribute and as the label for that checkbox. A single-element array has the same effect.
Each value can also be specified as a three-element array. The first element is the VALUE attribute; the second is the label; and the third is a boolean specifying whether this checkbox is CHECKED.
Each value can also be specified as a two-element array, by omitting either the value element (defaults to the same as the label), or the boolean checked element (defaults to false).
checkbox_group("name", "foo", "bar", "baz") # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz checkbox_group("name", ["foo"], ["bar", true], "baz") # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz") # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]) checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
Generate an Image Button Input element as a string.
src
is the URL of the image to use for the button. name
is the input name. alt
is the alternative text for the image.
Alternatively, the attributes can be specified as a hash.
image_button("url") # <INPUT TYPE="image" SRC="url"> image_button("url", "name", "string") # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string"> image_button("SRC" => "url", "ALT" => "string") # <INPUT TYPE="image" SRC="url" ALT="string">
Calls the block with each key/value pair:
res = Net::HTTP.get_response(hostname, '/todos/1') res.each_header do |key, value| p [key, value] if key.start_with?('c') end
Output:
["content-type", "application/json; charset=utf-8"] ["connection", "keep-alive"] ["cache-control", "max-age=43200"] ["cf-cache-status", "HIT"] ["cf-ray", "771d17e9bc542cf5-ORD"]
Returns an enumerator if no block is given.
Net::HTTPHeader#each
is an alias for Net::HTTPHeader#each_header
.
Calls the block with each field key:
res = Net::HTTP.get_response(hostname, '/todos/1') res.each_key do |key| p key if key.start_with?('c') end
Output:
"content-type" "connection" "cache-control" "cf-cache-status" "cf-ray"
Returns an enumerator if no block is given.
Net::HTTPHeader#each_name
is an alias for Net::HTTPHeader#each_key
.
Calls the block with each string field value:
res = Net::HTTP.get_response(hostname, '/todos/1') res.each_value do |value| p value if value.start_with?('c') end
Output:
"chunked" "cf-q-config;dur=6.0000002122251e-06" "cloudflare"
Returns an enumerator if no block is given.
Like each_header
, but the keys are returned in capitalized form.
Net::HTTPHeader#canonical_each
is an alias for Net::HTTPHeader#each_capitalized
.