Class: BlockCipherKit::CipherIO

Inherits:
Object
  • Object
show all
Defined in:
lib/block_cipher_kit/cipher_io.rb

Overview

Allows an OpenSSL::Cipher to be written through as if it were an IO. This allows the cipher to be passed to things like IO.copy_stream

Instance Method Summary collapse

Constructor Details

#initialize(io, cipher) ⇒ CipherIO

Returns a new instance of CipherIO.



4
5
6
7
# File 'lib/block_cipher_kit/cipher_io.rb', line 4

def initialize(io, cipher)
  @io = io
  @cipher = cipher
end

Instance Method Details

#write(bytes) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/block_cipher_kit/cipher_io.rb', line 9

def write(bytes)
  @io.write(@cipher.update(bytes))
  # We must return the amount of bytes of input
  # we have accepted, not the amount of bytes
  # of output we produced from the cipher
  bytes.bytesize
end