Class: Duse::Client::SecretMarshaller
- Inherits:
-
Object
- Object
- Duse::Client::SecretMarshaller
- Defined in:
- lib/duse/client/secret.rb
Instance Method Summary collapse
-
#initialize(secret, private_key) ⇒ SecretMarshaller
constructor
A new instance of SecretMarshaller.
- #parts_from_secret ⇒ Object
- #secret_text_in_slices_of(piece_size) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(secret, private_key) ⇒ SecretMarshaller
Returns a new instance of SecretMarshaller.
8 9 10 11 |
# File 'lib/duse/client/secret.rb', line 8 def initialize(secret, private_key) @secret = secret @private_key = private_key end |
Instance Method Details
#parts_from_secret ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/duse/client/secret.rb', line 20 def parts_from_secret # sliced of 18 is a result of trial & error, if it's too large then # encryption will fail. Might improve with: http://stackoverflow.com/questions/11505547/how-calculate-size-of-rsa-cipher-text-using-key-size-clear-text-length secret_text_in_slices_of(18).map do |secret_part| shares = SecretSharing.split_secret(secret_part, 2, @secret.users.length) @secret.users.each_with_index.map do |user, index| share = shares[index] content, signature = Duse::Encryption.encrypt(@private_key, user.public_key, share) {"user_id" => user.id, "content" => content, "signature" => signature} end end end |
#secret_text_in_slices_of(piece_size) ⇒ Object
33 34 35 36 |
# File 'lib/duse/client/secret.rb', line 33 def secret_text_in_slices_of(piece_size) encoded_secret = Encryption.encode(@secret.secret_text) encoded_secret.chars.each_slice(piece_size).map(&:join) end |
#to_h ⇒ Object
13 14 15 16 17 18 |
# File 'lib/duse/client/secret.rb', line 13 def to_h secret_hash = {} secret_hash['title'] = @secret.title if @secret.title secret_hash['parts'] = parts_from_secret if @secret.secret_text secret_hash end |