waylon-core 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44b2586a3ba29a3b2da02d66f880a826b445d2658ea6f83fa3e8a0a9935d0898
4
- data.tar.gz: b1d602e2f41f06c37752c31eb2d9a0a983f699f3bcd7c73372305719c6a68874
3
+ metadata.gz: 0d0e47ec62eadd0848b4538d1bb32238b7e769f09500d536925cbd7d4367be68
4
+ data.tar.gz: 0ecd0c0d42d07861138d8df7170cb49f9eab7bf9a142844bbca44c57d1222bff
5
5
  SHA512:
6
- metadata.gz: 6d40939e62fa6c4a58c7bf31ec716fdde3d0d878e36aa6331dcfdabd73b67b02b441973243a3baefd9c96ad01681a1ab382146d26ffa4de83db3ea41355a060f
7
- data.tar.gz: 581ba5ccbececbb637a09efab4bd202c3e8112edca8999e57e5fe3bda3b1cb40097f92c73d5e959c76c454039f9d7581fd13955580d5d72d0b3ba773b3991ca0
6
+ metadata.gz: a9dcad0d9c4ad06afa6579d0a38daa70733fc8a0c692fb9f12b52ddd49f4ab998768ffbd92bfe7fc3a54b5b6691f91f4719c882d730e824364ea5adb190119b3
7
+ data.tar.gz: 94867f2bb0fde6993ded3026d827c36dbc4af5e3979281a005feea6f202a2e59a700b72ad2bf368d16add33eee9e631451d9aba76b38eb38d04a9c422097e234
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waylon-core (0.2.3)
4
+ waylon-core (0.2.4)
5
5
  addressable (~> 2.8)
6
6
  faraday (~> 1.8)
7
7
  i18n (~> 1.8)
@@ -9,7 +9,7 @@ module Waylon
9
9
  )
10
10
 
11
11
  def self.cipher
12
- key_bytes = RbNaCl::Hash.sha256(ENV.fetch("ENCRYPTION_KEY", "thisisVeryUnsafe4U"))[0..31]
12
+ key_bytes = RbNaCl::Hash.sha256(encryption_key)[0..31]
13
13
  RbNaCl::SimpleBox.from_secret_key(key_bytes)
14
14
  end
15
15
 
@@ -21,6 +21,15 @@ module Waylon
21
21
  storage.delete(key)
22
22
  end
23
23
 
24
+ def self.encryption_key
25
+ ENV.fetch("ENCRYPTION_KEY", "thisisVeryUnsafe4U")
26
+ end
27
+
28
+ def self.encryption_key_fingerprint
29
+ base = RbNaCl::Hash.sha256(encryption_key)[0..15]
30
+ Base64.urlsafe_encode64(RbNaCl::Hash.sha256(base)[0..7])
31
+ end
32
+
24
33
  def self.key?(name)
25
34
  storage.key?(name)
26
35
  end
@@ -30,7 +39,11 @@ module Waylon
30
39
  raw = storage.load(key)
31
40
  return nil unless raw
32
41
 
33
- decoded = Base64.decode64(raw)
42
+ wrapper = JSON.parse(raw)
43
+ value = wrapper["data"]
44
+ return nil unless value
45
+
46
+ decoded = Base64.decode64(value)
34
47
  plain = this_cipher.decrypt(decoded)
35
48
  JSON.parse(plain)
36
49
  end
@@ -47,7 +60,8 @@ module Waylon
47
60
  this_cipher = cipher
48
61
  encrypted = this_cipher.encrypt(value.to_json)
49
62
  encoded = Base64.encode64(encrypted)
50
- storage.store(key, encoded)
63
+ wrapper = { cipher: cipher.class.name, data: encoded, key: encryption_key_fingerprint }
64
+ storage.store(key, wrapper.to_json)
51
65
  end
52
66
  end
53
67
  end
@@ -6,7 +6,7 @@ module Waylon
6
6
  VERSION = [
7
7
  0, # Major
8
8
  2, # Minor
9
- 3 # Patch
9
+ 4 # Patch
10
10
  ].join(".")
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waylon-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-30 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable