Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

vistahigherlearning / logstash   deb

Repository URL to install this package:

/ opt / logstash / vendor / bundle / jruby / 1.9 / gems / rbnacl-2.0.0 / lib / rbnacl / random.rb

require 'thread'

# encoding: binary
module RbNaCl
  # Functions for random number generation
  #
  # This uses the underlying source of random number generation on the OS, so
  # /dev/urandom on UNIX-like systems, and the MS crypto providor on windows.
  module Random
    extend Sodium

    @mutex = Mutex.new

    sodium_function :c_random_bytes,
                    :randombytes_buf,
                    [:pointer, :ulong_long]
    # Returns a string of random bytes
    #
    # @param [Integer] n number of random bytes desired
    #
    # @return [String] random bytes.
    def self.random_bytes(n=32)
      buf = RbNaCl::Util.zeros(n)
      @mutex.synchronize { c_random_bytes(buf, n) }
      buf
    end
  end
end