Class: Duse::Client::Secret

Inherits:
Entity
  • Object
show all
Defined in:
lib/duse/client/secret.rb

Constant Summary

Constants inherited from Entity

Entity::MAP

Instance Attribute Summary collapse

Attributes inherited from Entity

#attributes, #curry

Instance Method Summary collapse

Methods inherited from Entity

add_attribute, attributes, base_path, #delete, id_field, #initialize, #load_attribute, many, #missing?, one, #reload, #save, #set_attribute, subclasses

Constructor Details

This class inherits a constructor from Duse::Client::Entity

Instance Attribute Details

#secret_textObject

Returns the value of attribute secret_text.



43
44
45
# File 'lib/duse/client/secret.rb', line 43

def secret_text
  @secret_text
end

Instance Method Details

#decrypt(private_key) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/duse/client/secret.rb', line 49

def decrypt(private_key)
  unless self.secret_text
    secret_text = parts(private_key).inject('') do |result, shares|
      result << SecretSharing.recover_secret(shares)
    end
    self.secret_text = Encryption.decode(secret_text)
  end
  self.secret_text
end

#parts(private_key) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/duse/client/secret.rb', line 59

def parts(private_key)
  return nil if load_attribute('parts').nil?
  load_attribute('parts').map do |part|
    part.map do |share|
      Duse::Encryption.decrypt private_key, share
    end
  end
end