Class: Sodium::SecretBuffer
- Inherits:
-
Object
- Object
- Sodium::SecretBuffer
- Extended by:
- Forwardable
- Defined in:
- lib/sodium/secret_buffer.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#to_ptr ⇒ Object
readonly
Returns the value of attribute to_ptr.
Instance Method Summary collapse
- #free ⇒ Object
-
#initialize(size) ⇒ SecretBuffer
constructor
A new instance of SecretBuffer.
- #noaccess ⇒ Object
- #readonly ⇒ Object
- #readwrite ⇒ Object
Constructor Details
#initialize(size) ⇒ SecretBuffer
Returns a new instance of SecretBuffer.
13 14 15 16 17 |
# File 'lib/sodium/secret_buffer.rb', line 13 def initialize(size) @size = Integer(size) @to_ptr = Sodium.malloc(@size) ObjectSpace.define_finalizer(@to_ptr, self.class.free(@to_ptr.address)) end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
10 11 12 |
# File 'lib/sodium/secret_buffer.rb', line 10 def size @size end |
#to_ptr ⇒ Object (readonly)
Returns the value of attribute to_ptr.
10 11 12 |
# File 'lib/sodium/secret_buffer.rb', line 10 def to_ptr @to_ptr end |
Instance Method Details
#free ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/sodium/secret_buffer.rb', line 19 def free Sodium::Mprotect.readonly(@to_ptr) Sodium.free(@to_ptr) ObjectSpace.undefine_finalizer @to_ptr remove_instance_variable(:@size) remove_instance_variable(:@to_ptr) true end |
#noaccess ⇒ Object
28 29 30 |
# File 'lib/sodium/secret_buffer.rb', line 28 def noaccess Sodium::Mprotect.noaccess(@to_ptr) end |