Class: CcipherFactory::SoftSymKey

Inherits:
Object
  • Object
show all
Includes:
Common, SymKey, TR::CondUtils
Defined in:
lib/ccipher_factory/symkey/soft_symkey.rb

Instance Attribute Summary

Attributes included from SymKey

#key, #keysize, #keytype

Class Method 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

Methods included from SymKey

#dispose, #is_equals?, #merge_key, #raw_key, #split_key

Methods included from ShamirSharingHelper

#shamir_recover, #shamir_split

Constructor Details

#initialize(keytype, keysize, key = nil) ⇒ SoftSymKey

Mixin methods



40
41
42
# File 'lib/ccipher_factory/symkey/soft_symkey.rb', line 40

def initialize(keytype, keysize, key = nil)
  super(keytype, keysize, key)
end

Class Method Details

.from_encoded(bin, &block) ⇒ Object



10
11
12
13
# File 'lib/ccipher_factory/symkey/soft_symkey.rb', line 10

def self.from_encoded(bin, &block)
  ts = BinStruct.instance.struct_from_bin(bin)
  from_tspec(ts, &block)
end

.from_tspec(ts, &block) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ccipher_factory/symkey/soft_symkey.rb', line 15

def self.from_tspec(ts, &block)
  
  #raise SymKeyError, "Given envelope not symkey enveloppe [#{ts.id}]" if ts.id != :symkey
  raise SymKeyError, "Given envelope not symkey enveloppe [#{ts.oid}]" if ts.oid != BTag.constant_value(:symkey)

  #keytype = Tag.constant_key(ts.value(:keytype))
  #keysize = ts.value(:keysize)
  #key = ts.value(:key)

  keytype = BTag.value_constant(ts.keytype)
  keysize = ts.keysize
  key = ts.key
  if is_empty?(key)
    if not block
      raise SymKeyError, "Key is not in the meta data. Key is required to complete the construction of the object"
    end
    key = block.call(:key)
  end

  SoftSymKey.new(keytype, keysize, key) 
end

Instance Method Details

#encodedObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ccipher_factory/symkey/soft_symkey.rb', line 44

def encoded
  ts = BinStruct.instance.struct(:symkey)
  ts.keytype = BTag.constant_value(@keytype)
  ts.keysize = @keysize
  if is_attach_mode? 
    case @key
    when String
      ts.key = @key
    else
      ts.key = @key.to_bin
    end
  else
    ts.key = ""
  end
  ts.encoded

end