Class: Sodium::Buffer::ZeroingDelegator

Inherits:
Object
  • Object
show all
Defined in:
lib/sodium/buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(string, &finalizer) ⇒ ZeroingDelegator

Returns a new instance of ZeroingDelegator.



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/sodium/buffer.rb', line 207

def initialize(string, &finalizer)
  # specify class name explicitly, since we're letting the `class`
  # method delegate to the wrapped object
  Sodium::Buffer::ZeroingDelegator._mlock!          string, string.bytesize
  Sodium::Buffer::ZeroingDelegator._finalize! self, string, string.bytesize,
    &finalizer

  self.__setobj__(string)
  self.__getobj__.freeze
  self           .freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (protected)



237
238
239
240
241
242
243
244
245
# File 'lib/sodium/buffer.rb', line 237

def method_missing(*args, &block)
  self.__getobj__.__send__(*args, &block)
ensure
  $@.delete_if do |trace|
    # delete lines from the backtrace that originate from the
    # __send__ line above
    trace =~ %r{ \A #{Regexp.quote(__FILE__)}:#{__LINE__ - 5} : }x
  end if $@
end

Instance Method Details

#to_sObject Also known as: dup, clone



219
220
221
# File 'lib/sodium/buffer.rb', line 219

def to_s
  self
end

#to_strObject



223
224
225
226
227
228
229
230
# File 'lib/sodium/buffer.rb', line 223

def to_str
  # Okay, fine, you win. I'll give you access to the raw string
  # we're wrapping. But now I can't wipe the data when you're done
  # with it.
  self.__getobj__.
    tr('', ''). # trick to force the string to be copied
    freeze
end