Class: E3DCMqtt::RSCP::Rijndael256::CBCDecryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/e3dc_mqtt/rscp/rijndael256.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, iv) ⇒ CBCDecryptor

Returns a new instance of CBCDecryptor.

Raises:

  • (ArgumentError)


222
223
224
225
226
227
# File 'lib/e3dc_mqtt/rscp/rijndael256.rb', line 222

def initialize(key, iv)
  raise ArgumentError, "IV must be #{BLOCK_SIZE} bytes" if iv.bytesize != BLOCK_SIZE

  @cipher = Cipher.new(key)
  @iv = iv.dup.force_encoding(Encoding::BINARY)
end

Instance Method Details

#update(ciphertext) ⇒ Object

Raises:

  • (ArgumentError)


229
230
231
232
233
234
235
236
237
238
239
# File 'lib/e3dc_mqtt/rscp/rijndael256.rb', line 229

def update(ciphertext)
  raise ArgumentError, "ciphertext must be a multiple of #{BLOCK_SIZE} bytes" unless (ciphertext.bytesize % BLOCK_SIZE).zero?

  out = String.new(capacity: ciphertext.bytesize, encoding: Encoding::BINARY)
  (0...ciphertext.bytesize).step(BLOCK_SIZE) do |i|
    block = ciphertext.byteslice(i, BLOCK_SIZE)
    out << Rijndael256.xor_bytes(@cipher.decrypt_block(block), @iv)
    @iv = block
  end
  out
end