Class: Botan::RNG
- Inherits:
-
Object
- Object
- Botan::RNG
- Defined in:
- lib/botan/rng.rb
Overview
Random Number Generator
Instance Attribute Summary collapse
- #ptr ⇒ Object readonly private
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
-
.get(length) ⇒ String
Retrieves some data from the default RNG.
Instance Method Summary collapse
-
#get(length) ⇒ String
Retrieves some data from the RNG.
-
#initialize(rng_type = nil) ⇒ RNG
constructor
A new instance of RNG.
- #inspect ⇒ Object
-
#reseed(bits = 256) ⇒ self
Reseeds the RNG from the system RNG.
Constructor Details
#initialize(rng_type = nil) ⇒ RNG
Returns a new instance of RNG.
17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#ptr ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/botan/rng.rb', line 15 def ptr @ptr end |
Class Method Details
.destroy(ptr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/botan/rng.rb', line 26 def self.destroy(ptr) LibBotan.botan_rng_destroy(ptr) end |
Instance Method Details
#get(length) ⇒ String
Retrieves some data from the RNG.
51 52 53 54 55 |
# 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 ⇒ Object
57 58 59 |
# File 'lib/botan/rng.rb', line 57 def inspect Botan.inspect_ptr(self) end |