Module: CcipherFactory::SymKeySigner::SymKeySign

Includes:
Common, TR::CondUtils
Defined in:
lib/ccipher_factory/symkey_cipher/symkey_sign.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

#digest_algoObject

Returns the value of attribute digest_algo.



13
14
15
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 13

def digest_algo
  @digest_algo
end

#signing_keyObject

Returns the value of attribute signing_key.



13
14
15
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 13

def signing_key
  @signing_key
end

Instance Method Details

#initObject



15
16
17
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 15

def init
  @digest_algo = Digest::SupportedDigest.instance.default_digest
end

#loggerObject



59
60
61
62
63
64
65
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 59

def logger
  if @logger.nil?
    @logger = Tlogger.new
    @logger.tag = :symkey_sign
  end
  @logger
end

#sign_finalObject

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 46

def sign_final

  raise SymKeySignerError, "Please call sign_init before sign_update" if @hmac.nil?

  sign = @hmac.hmac_final

  ts = BinStruct.instance.struct(:symkey_signature) 
  ts.digest_algo = BTag.constant_value(@digest_algo)
  ts.signature = sign
  ts.encoded

end

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

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 19

def sign_init(opts = { }, &block)

  raise SymKeySignerError, "Signing symkey is required" if is_empty?(@signing_key)
  raise SymKeySignerError, "Given digest algo is not supported" if not Digest::SupportedDigest.instance.is_supported?(@digest_algo)

  hconf = Ccrypto::HMACConfig.new
  hconf.key = Ccrypto::SecretKey.new(@signing_key.keytype, @signing_key.key)
  hconf.digest = @digest_algo

  @hmac = Ccrypto::AlgoFactory.engine(hconf)

  #@hmac = OpenSSL::HMAC.new(@signing_key.key, OpenSSL::Digest.new(Digest.to_digest_string(@digest_algo)))

  if block
    instance_eval(&block)
    sign_final
  else
    self
  end

end

#sign_update(val) ⇒ Object

Raises:



41
42
43
44
# File 'lib/ccipher_factory/symkey_cipher/symkey_sign.rb', line 41

def sign_update(val)
  raise SymKeySignerError, "Please call sign_init before sign_update" if @hmac.nil?
  @hmac.hmac_update(val)
end