Module: CcipherFactory::SymKeyCipher::SymKeyAttDecrypt

Includes:
Common
Defined in:
lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#attach_mode, #cleanup_intOutputBuf, #cleanup_intOutputFile, #detach_mode, #disposeOutput, #intOutputBuf, #intOutputFile, #is_attach_mode?, #is_output_given?, #output, #output_obj, #sanitize_symbol, #write_to_output

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb', line 8

def key
  @key
end

Instance Method Details

#att_decrypt_finalObject



50
51
52
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb', line 50

def att_decrypt_final
  @dec.decrypt_final
end

#att_decrypt_init(*args, &block) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb', line 9

def att_decrypt_init(*args, &block)

  raise SymKeyCipherError, "Output is required for attached decryption" if not is_output_given?

  @initParams = args

  if block
    instance_eval(&block)
    att_decrypt_final
  else
    self
  end

end

#att_decrypt_update(val) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_decrypt.rb', line 24

def att_decrypt_update(val)
  if @dec.nil?
    intOutputBuf.write(val)
    begin
      Encoding.extract_meta(intOutputBuf) do |meta, bal|

        @dec = SymKeyCipher.decryptor
        @dec.output(@output)
        @dec.key = @key
        @dec.decrypt_init(*@initParams)
        @dec.decrypt_update_meta(meta)

        logger.tdebug :att_dec, "Balance has data length #{bal.length}"
        att_decrypt_update(bal) if bal.length > 0

        disposeOutput(intOutputBuf)

      end
    rescue Encoding::InsufficientData => e
    end
  else
    logger.tdebug :att_dec, "Updating cipher size #{val.length}"
    @dec.decrypt_update_cipher(val)
  end
end