This library is an interface to secure random number generators which are suitable for generating session keys in HTTP cookies, etc.
You can use this library in your application by requiring it:
require 'securerandom'
It supports the following secure random number generators:
openssl
/dev/urandom
SecureRandom
is extended by the Random::Formatter
module which defines the following methods:
alphanumeric
base64
choose
hex
rand
random_bytes
random_number
urlsafe_base64
uuid
These methods are usable as class methods of SecureRandom
such as ‘SecureRandom.hex`.
Generate random hexadecimal strings:
require 'securerandom' SecureRandom.hex(10) #=> "52750b30ffbc7de3b362" SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559" SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23"
Generate random base64 strings:
SecureRandom.base64(10) #=> "EcmTPZwWRAozdA==" SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg==" SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8"
Generate random binary strings:
SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301" SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
Generate alphanumeric strings:
SecureRandom.alphanumeric(10) #=> "S8baxMJnPl" SecureRandom.alphanumeric(10) #=> "aOxAg8BAJe"
Generate UUIDs:
SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594" SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
This is not an existing class, but documentation of the interface that Scheduler object should comply in order to be used as Fiber.scheduler
and handle non-blocking fibers. See also the “Non-blocking fibers” section in Fiber
class docs for explanations of some concepts.
Scheduler’s behavior and usage are expected to be as follows:
When the execution in the non-blocking Fiber
reaches some blocking operation (like sleep, wait for a process, or a non-ready I/O), it calls some of the scheduler’s hook methods, listed below.
Scheduler somehow registers what the current fiber is waited for, and yields control to other fibers with Fiber.yield
(so the fiber would be suspended while expecting its wait to end, and other fibers in the same thread can perform)
At the end of the current thread execution, the scheduler’s method close
is called
The scheduler runs into a wait loop, checking all the blocked fibers (which it has registered on hook calls) and resuming them when the awaited resource is ready (I/O ready, sleep time passed).
A typical implementation would probably rely for this closing loop on a gem like EventMachine or Async.
This way concurrent execution will be achieved in a way that is transparent for every individual Fiber’s code.
Hook methods are:
(the list is expanded as Ruby developers make more methods having non-blocking calls)
When not specified otherwise, the hook implementations are mandatory: if they are not implemented, the methods trying to call hook will fail. To provide backward compatibility, in the future hooks will be optional (if they are not implemented, due to the scheduler being created for the older Ruby version, the code which needs this hook will not fail, and will just behave in a blocking fashion).
It is also strongly suggested that the scheduler implement the fiber
method, which is delegated to by Fiber.schedule
.
Sample toy implementation of the scheduler can be found in Ruby’s code, in test/fiber/scheduler.rb
Cleared reference exception
This exception is raised if a parser error occurs.
This exception is raised if the nesting of parsed data structures is too deep.
General error for openssl library configuration files. Including formatting, parsing errors, etc.
Subclass of Zlib::Error
When zlib returns a Z_VERSION_ERROR, usually if the zlib library version is incompatible with the version assumed by the caller.
Subclass of Zlib::Error
. This error is raised when the zlib stream is currently in progress.
For example:
inflater = Zlib::Inflate.new inflater.inflate(compressed) do inflater.inflate(compressed) # Raises Zlib::InProgressError end
Note: Don’t use this class directly. This is an internal class.
Error raised by the DRb
module when an attempt is made to refer to the context’s current drb server but the context does not have one. See current_server.
Class
representing a drb server instance.
A DRbServer must be running in the local process before any incoming dRuby calls can be accepted, or any local objects can be passed as dRuby references to remote processes, even if those local objects are never actually called remotely. You do not need to start a DRbServer in the local process if you are only making outgoing dRuby calls passing marshalled parameters.
Unless multiple servers are being used, the local DRbServer is normally started by calling DRb.start_service
.
HTTPGenericRequest
is the parent of the Net::HTTPRequest
class. Do not use this directly; use a subclass of Net::HTTPRequest
.
Mixes in the Net::HTTPHeader
module to provide easier access to HTTP headers.
Represents SMTP
error code 4xx, a temporary error.
An abstract class for enumerating pseudo-prime numbers.
Concrete subclasses should override succ, next, rewind.
An implementation of PseudoPrimeGenerator
which uses a prime table generated by trial division.
Generates all integers which are greater than 2 and are not divisible by either 2 or 3.
This is a pseudo-prime generator, suitable on checking primality of an integer by brute force method.