Module: CcipherFactory::SymKeySigner::SymKeyAttSign

Includes:
Common, Compression::CompressionHelper
Defined in:
lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Compression::CompressionHelper

#compress_data_if_active, #compression_off, #compression_on, #compressor, #decompress_data_if_active, #decompressor, #decompressor_from_encoded, #encode_null_compressor, #is_compression_on?

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

#signing_keyObject

Returns the value of attribute signing_key.



14
15
16
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb', line 14

def signing_key
  @signing_key
end

Instance Method Details

#att_sign_finalObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb', line 44

def att_sign_final

  meta = @signer.sign_final

  #ts = Encoding::ASN1Encoder.instance(:symkey_att_sign)
  ts = BinStruct.instance.struct(:symkey_att_sign)
  ts.symkey_signature = meta

  if is_compression_on?
    compRes = compressor.compress_final
    ts.compression = compRes
  else
    ts.compression = encode_null_compressor
  end

  attMeta = ts.encoded

  write_to_output(attMeta)
  intOutputFile.rewind
  while not intOutputFile.eof?
    write_to_output(intOutputFile.read)
  end

  logger.tdebug :symkey_att_sign, "Total Plain : #{@totalPlain} / Total Compressed : #{@totalCompressed} = #{(@totalCompressed*1.0)/@totalPlain*100} %" if is_compression_on?

  intOutputFile.close!

  attMeta

end

#att_sign_init(opts = { }, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb', line 16

def att_sign_init(opts = { }, &block)

  @signer = SymKeySigner.signer
  @signer.signing_key = @signing_key
  @signer.sign_init(opts)

  @totalPlain = 0
  @totalCompressed = 0

  if block
    instance_eval(&block)
    att_sign_final
  else
    self
  end

end

#att_sign_update(val) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb', line 34

def att_sign_update(val)
  raise SymKeySignerError, "Output is required for attached sign" if not is_output_given?

  @totalPlain += val.length
  @signer.sign_update(val)
  res = compress_data_if_active(val)
  intOutputFile.write(res)
  @totalCompressed += res.length
end

#loggerObject



75
76
77
78
79
80
# File 'lib/ccipher_factory/symkey_cipher/symkey_att_sign.rb', line 75

def logger
  if @logger.nil?
    @logger = Tlogger.new
  end
  @logger
end