Class List Method List File List

# Class: VertxAuthCommon::VertxContextPRNG

Inherits:
  Object
  - Object
  - VertxAuthCommon::VertxContextPRNG
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/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(vertx = nil)
  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
  Returns a secure random int.
- - (String) next_string(length = nil)
  Returns a Base64 mime encoded String of random data with the given length.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    24
    25
    26
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 24

    def @@j_api_type.accept?(obj)
      obj.class == VertxContextPRNG
    end

### + (`::VertxAuthCommon::VertxContextPRNG`) current(vertx = nil)

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.

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  a Vert.x instance.

Returns:

- (`::VertxAuthCommon::VertxContextPRNG`) —
  A secure non blocking random number generator.

Raises:

- (`ArgumentError`)

    44
    45
    46
    47
    48
    49
    50
    51
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 44

    def self.current(vertx=nil)
      if !block_given? && vertx == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuth::VertxContextPRNG.java_method(:current, []).call(),::VertxAuthCommon::VertxContextPRNG)
      elsif vertx.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(vertx.j_del),::VertxAuthCommon::VertxContextPRNG)
      end
      raise ArgumentError, "Invalid arguments when calling current(#{vertx})"
    end

### + (`Object`) j_api_type

    33
    34
    35
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 33

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    36
    37
    38
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 36

    def self.j_class
      Java::IoVertxExtAuth::VertxContextPRNG.java_class
    end

### + (`Object`) unwrap(obj)

    30
    31
    32
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 30

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    27
    28
    29
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 27

    def @@j_api_type.wrap(obj)
      VertxContextPRNG.new(obj)
    end

## Instance Method Details

### - (`Fixnum`) next_int

Returns a secure random int

Returns:

- (`Fixnum`) —
  random int.

Raises:

- (`ArgumentError`)

    64
    65
    66
    67
    68
    69
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 64

    def next_int
      if !block_given?
        return @j_del.java_method(:nextInt, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling next_int()"
    end

### - (`String`) next_string(length = nil)

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.

Parameters:

- length (`Fixnum`) (defaults to: `nil`) —
  the desired string length before Base64 encoding.

Returns:

- (`String`) —
  A base 64 encoded string.

Raises:

- (`ArgumentError`)

    56
    57
    58
    59
    60
    61
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/vertx_context_prng.rb', line 56

    def next_string(length=nil)
      if length.class == Fixnum && !block_given?
        return @j_del.java_method(:nextString, [Java::int.java_class]).call(length)
      end
      raise ArgumentError, "Invalid arguments when calling next_string(#{length})"
    end