Class: Ccrypto::Ruby::MemoryBuffer
- Inherits:
-
Object
- Object
- Ccrypto::Ruby::MemoryBuffer
- Defined in:
- lib/ccrypto/ruby/utils/memory_buffer.rb
Instance Method Summary collapse
- #bytes ⇒ Object
- #dispose(wcnt = 32) ⇒ Object
- #equals?(val) ⇒ Boolean
-
#initialize(*args, &block) ⇒ MemoryBuffer
constructor
A new instance of MemoryBuffer.
- #length ⇒ Object
- #pos ⇒ Object
- #read(len) ⇒ Object
- #respond_to_missing?(mtd, *args, &block) ⇒ Boolean
- #rewind ⇒ Object
- #write(val) ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ MemoryBuffer
Returns a new instance of MemoryBuffer.
7 8 9 10 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 7 def initialize(*args,&block) @buf = StringIO.new @buf.binmode end |
Instance Method Details
#bytes ⇒ Object
12 13 14 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 12 def bytes @buf.string end |
#dispose(wcnt = 32) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 28 def dispose(wcnt = 32) len = @buf.length cnt = 0 loop do @buf.rewind @buf.write(SecureRandom.random_bytes(len)) cnt += 1 break if cnt >= wcnt end @buffer = nil GC.start end |
#equals?(val) ⇒ Boolean
57 58 59 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 57 def equals?(val) bytes == val end |
#length ⇒ Object
20 21 22 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 20 def length @buf.length end |
#pos ⇒ Object
16 17 18 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 16 def pos @buf.pos end |
#read(len) ⇒ Object
49 50 51 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 49 def read(len) @buf.read(len) end |
#respond_to_missing?(mtd, *args, &block) ⇒ Boolean
53 54 55 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 53 def respond_to_missing?(mtd, *args, &block) @buf.respond_to?(mtd, *args, &block) end |
#rewind ⇒ Object
24 25 26 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 24 def rewind @buf.rewind end |
#write(val) ⇒ Object
45 46 47 |
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 45 def write(val) @buf.write(val) end |