Class: BlockCipherKit::CipherIO
- Inherits:
-
Object
- Object
- BlockCipherKit::CipherIO
- 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 :nodoc:
Instance Method Summary collapse
-
#initialize(io, cipher) ⇒ CipherIO
constructor
A new instance of CipherIO.
- #write(bytes) ⇒ Object
Constructor Details
#initialize(io, cipher) ⇒ CipherIO
Returns a new instance of CipherIO.
5 6 7 8 |
# File 'lib/block_cipher_kit/cipher_io.rb', line 5 def initialize(io, cipher) @io = io @cipher = cipher end |
Instance Method Details
#write(bytes) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/block_cipher_kit/cipher_io.rb', line 10 def write(bytes) # OpenSSL ciphers fail if you update() them with an empty buffer return 0 if bytes.bytesize.zero? @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 |