Class: VertxAuthCommon::VertxContextPRNG
- Inherits:
-
Object
- Object
- VertxAuthCommon::VertxContextPRNG
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb
Overview
A secure non blocking random number generator isolated to the current context. The PRNG is bound to the vert.x
context and setup to close when the context shuts down.
When applicable, use of VertxContextPRNG rather than create new PRNG objects is helpful to keep the system entropy usage to the minimum avoiding potential blocking across the application.
The use of VertxContextPRNG is particularly appropriate when multiple handlers use random numbers.
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
-
+ (::VertxAuthCommon::VertxContextPRNG) current(*args)
Get or create a secure non blocking random number generator using the current vert.x instance.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (Fixnum) next_int(*args)
Returns a secure random int, between 0 (inclusive) and the specified bound (exclusive).
-
- (String) nextString(length)
Returns a Base64 mime encoded String of random data with the given length.
Class Method Details
+ (Boolean) accept?(obj)
25 26 27 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 25 def @@j_api_type.accept?(obj) obj.class == VertxContextPRNG end |
+ (::VertxAuthCommon::VertxContextPRNG) current + (::VertxAuthCommon::VertxContextPRNG) current(vertx)
Get or create a secure non blocking random number generator using the current vert.x instance. Since the context
might be different this method will attempt to use the current context first if available and then fall back to
create a new instance of the PRNG.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 47 def self.current(*args) if !block_given? && args[0] == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuth::VertxContextPRNG.java_method(:current, []).call(),::VertxAuthCommon::VertxContextPRNG) elsif args[0].class.method_defined?(:j_del) && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuth::VertxContextPRNG.java_method(:current, [Java::IoVertxCore::Vertx.java_class]).call(args[0].j_del),::VertxAuthCommon::VertxContextPRNG) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling current(#{args[0]})" end end |
+ (Object) j_api_type
34 35 36 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 34 def self.j_api_type @@j_api_type end |
+ (Object) j_class
37 38 39 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 37 def self.j_class Java::IoVertxExtAuth::VertxContextPRNG.java_class end |
+ (Object) unwrap(obj)
31 32 33 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 31 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
28 29 30 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 28 def @@j_api_type.wrap(obj) VertxContextPRNG.new(obj) end |
Instance Method Details
- (Fixnum) nextInt - (Fixnum) nextInt(bound)
Returns a secure random int, between 0 (inclusive) and the specified bound (exclusive).
64 65 66 67 68 69 70 71 72 73 74 75 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 64 def next_int(*args) if !block_given? && args[0] == nil return @j_del.java_method(:nextInt, []).call() elsif args[0].class == Fixnum && !block_given? return @j_del.java_method(:nextInt, [Java::int.java_class]).call(args[0]) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling next_int(#{args[0]})" end end |
- (String) nextString(length)
Returns a Base64 mime encoded String of random data with the given length. The length parameter refers to the length
of the String before the encoding step.
81 82 83 84 85 86 87 88 89 90 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/vertx_context_prng.rb', line 81 def next_string(*args) if args[0].class == Fixnum && !block_given? return @j_del.java_method(:nextString, [Java::int.java_class]).call(args[0]) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling next_string(#{args[0]})" end end |