Class: Ccrypto::Ruby::MemoryBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/ccrypto/ruby/utils/memory_buffer.rb

Instance Method Summary collapse

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

#bytesObject



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

Returns:

  • (Boolean)


57
58
59
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 57

def equals?(val)
  bytes == val
end

#lengthObject



20
21
22
# File 'lib/ccrypto/ruby/utils/memory_buffer.rb', line 20

def length
  @buf.length
end

#posObject



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

Returns:

  • (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

#rewindObject



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