selfsdk 0.0.140 → 0.0.141

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crypto.rb +15 -5
  3. data/lib/messaging.rb +2 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 031a8f44592664c22d59c7c1105822ab9111dde46ffda50ba34b6116d70d4a3f
4
- data.tar.gz: e2096831cb8f8d5bcba45fabf93a5173fac96f06ec933b6f6d446d1ed55f015a
3
+ metadata.gz: 1fc84c8ad47b159c7f07f33226c1273bf30202f3b999ceba02ef51f6b35763fb
4
+ data.tar.gz: 4c88fbad5ffa05cc69977554d454ca7fcc796663400f2e74b770879afe05c2a7
5
5
  SHA512:
6
- metadata.gz: 368a7cdacf1df7204473e6488e299e06e40b6caacc332c366ca039fea96930186e4888e007a333e99a6693d9b6ae18d13b4ae339f7d2cd988a1c412826bfce47
7
- data.tar.gz: bc484da9425cc8e9f3b4d7e7af132f15395b1966109636e941ff3b5592ace7d914b65f338de4287de96e8d1d92dac03d5555667f1e146311a4965975b3154888
6
+ metadata.gz: c5f9b8cf446fb87a089d2094449691cd73806af84ce5d3f712a0357a0bdc5c4b2f7fef0dd6552591d56c4c5dd07fcaadcad02173b67b500f07ae80aec519fc2f
7
+ data.tar.gz: ee291b8ca0f22787067ae2edca5a59fee3fea4950a06cfd921c00c9d283d7c769cefeac7dd8bcee0bd2eeee7784fab307a52919d81f87942b8c8ccd4eff6d045
@@ -8,9 +8,9 @@ module SelfSDK
8
8
  @storage_key = storage_key
9
9
  @storage_folder = storage_folder
10
10
 
11
- if File.exist?('account.pickle')
11
+ if File.exist?(account_path)
12
12
  # 1a) if alice's account file exists load the pickle from the file
13
- @account = SelfCrypto::Account.from_pickle(File.read('account.pickle'), @storage_key)
13
+ @account = SelfCrypto::Account.from_pickle(File.read(account_path), @storage_key)
14
14
  else
15
15
  # 1b-i) if create a new account for alice if one doesn't exist already
16
16
  @account = SelfCrypto::Account.from_seed(@client.jwt.key)
@@ -25,12 +25,12 @@ module SelfSDK
25
25
  @client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys)
26
26
 
27
27
  # 1b-v) store the account to a file
28
- File.write('account.pickle', @account.to_pickle(storage_key))
28
+ File.write(account_path, @account.to_pickle(storage_key))
29
29
  end
30
30
  end
31
31
 
32
32
  def encrypt(message, recipient, recipient_device)
33
- session_file_name = "#{recipient}:#{recipient_device}-session.pickle"
33
+ session_file_name = session_path(recipient, recipient_device)
34
34
 
35
35
  if File.exist?(session_file_name)
36
36
  # 2a) if bob's session file exists load the pickle from the file
@@ -71,7 +71,7 @@ module SelfSDK
71
71
  end
72
72
 
73
73
  def decrypt(message, sender, sender_device)
74
- session_file_name = "#{sender}:#{sender_device}-session.pickle"
74
+ session_file_name = session_path(sender, sender_device)
75
75
 
76
76
  if File.exist?(session_file_name)
77
77
  # 7a) if carol's session file exists load the pickle from the file
@@ -98,5 +98,15 @@ module SelfSDK
98
98
  # 10) decrypt the message ciphertext
99
99
  gs.decrypt("#{sender}:#{sender_device}", message).to_s
100
100
  end
101
+
102
+ private
103
+
104
+ def account_path
105
+ "#{@storage_folder}/account.pickle"
106
+ end
107
+
108
+ def session_path(selfid, device)
109
+ "#{@storage_folder}/#{selfid}:#{device}-session.pickle"
110
+ end
101
111
  end
102
112
  end
@@ -30,7 +30,7 @@ module SelfSDK
30
30
  # @params storage_folder [String] folder to perist messaging encryption
31
31
  # @option opts [Bool] :auto_reconnect Automatically reconnects to websocket if connection is lost (defaults to true).
32
32
  # @option opts [String] :device_id The device id to be used by the app defaults to "1".
33
- def initialize(url, client, storage_key, storage_folder, options = {})
33
+ def initialize(url, client, storage_key, options = {})
34
34
  @mon = Monitor.new
35
35
  @url = url
36
36
  @messages = {}
@@ -49,7 +49,7 @@ module SelfSDK
49
49
 
50
50
  FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
51
51
  unless options.include? :no_crypto
52
- @encryption_client = Crypto.new(@client, @device_id, storage_folder, storage_key)
52
+ @encryption_client = Crypto.new(@client, @device_id, @storage_dir, storage_key)
53
53
  end
54
54
 
55
55
  if options.include? :ws
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.140
4
+ version: 0.0.141
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures