class Botan::RNG
Random Number Generator
Attributes
ptr[R]
@api private
Public Class Methods
destroy(ptr)
click to toggle source
@api private
# File lib/botan/rng.rb, line 26 def self.destroy(ptr) LibBotan.botan_rng_destroy(ptr) end
get(length)
click to toggle source
Retrieves some data from the default RNG
.
@param length [Integer] the number of bytes to retrieve @return [String]
# File lib/botan/rng.rb, line 34 def self.get(length) RNG.new.get(length) end
new(rng_type = nil)
click to toggle source
@param rng_type [String] the type of RNG
to create
# File lib/botan/rng.rb, line 17 def initialize(rng_type = nil) ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_rng_init, ptr, rng_type) ptr = ptr.read_pointer raise Botan::Error, 'botan_rng_init returned NULL' if ptr.null? @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) end
Public Instance Methods
get(length)
click to toggle source
Retrieves some data from the RNG
.
@param length [Integer] the number of bytes to retrieve @return [String]
# File lib/botan/rng.rb, line 51 def get(length) out_buf = FFI::MemoryPointer.new(:uint8, length) Botan.call_ffi(:botan_rng_get, @ptr, out_buf, length) out_buf.read_bytes(length) end
inspect()
click to toggle source
# File lib/botan/rng.rb, line 57 def inspect Botan.inspect_ptr(self) end