waylon-core 0.2.3 → 0.2.6

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: f127e3f8c3b91cd3d00f5d394ed63e1280d4e84c05f27e6f1526f44edc7b546a
4
+ data.tar.gz: 44efb8ef9ee90fb8480d873a1a87faad240936085ac379dc634eb81e255792c2
5
5
  SHA512:
6
- metadata.gz: 6d40939e62fa6c4a58c7bf31ec716fdde3d0d878e36aa6331dcfdabd73b67b02b441973243a3baefd9c96ad01681a1ab382146d26ffa4de83db3ea41355a060f
7
- data.tar.gz: 581ba5ccbececbb637a09efab4bd202c3e8112edca8999e57e5fe3bda3b1cb40097f92c73d5e959c76c454039f9d7581fd13955580d5d72d0b3ba773b3991ca0
6
+ metadata.gz: 53170a69a5676f06c4ec93eda0766728a4c2ee94e1333f82f22b551862af84d6b6407fa3521579c9b8f27681fe575c6073dbf0cd4c5008d9cf3613149e69fef0
7
+ data.tar.gz: 52b0a7aa10408bef47cbcf0a12e6d517e5e2c9d8012f0ee2fbd83139826cea53f727c6bb4698820bfbe95040103376284dda9c1f4103f5407f74d5944a871a98
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.6)
5
5
  addressable (~> 2.8)
6
6
  faraday (~> 1.8)
7
7
  i18n (~> 1.8)
@@ -73,7 +73,7 @@ GEM
73
73
  rake (13.0.6)
74
74
  rbnacl (7.1.1)
75
75
  ffi
76
- redis (5.0.1)
76
+ redis (5.0.2)
77
77
  redis-client (~> 0.7)
78
78
  redis-client (0.7.1)
79
79
  connection_pool
data/lib/waylon/cache.rb CHANGED
@@ -8,6 +8,10 @@ module Waylon
8
8
  url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1"
9
9
  )
10
10
 
11
+ def self.adapter
12
+ storage.adapter
13
+ end
14
+
11
15
  def self.clear
12
16
  storage.clear
13
17
  end
@@ -8,8 +8,12 @@ module Waylon
8
8
  url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/2"
9
9
  )
10
10
 
11
+ def self.adapter
12
+ storage.adapter
13
+ end
14
+
11
15
  def self.cipher
12
- key_bytes = RbNaCl::Hash.sha256(ENV.fetch("ENCRYPTION_KEY", "thisisVeryUnsafe4U"))[0..31]
16
+ key_bytes = RbNaCl::Hash.sha256(encryption_key)[0..31]
13
17
  RbNaCl::SimpleBox.from_secret_key(key_bytes)
14
18
  end
15
19
 
@@ -21,6 +25,19 @@ module Waylon
21
25
  storage.delete(key)
22
26
  end
23
27
 
28
+ def self.each_key(&block)
29
+ storage.each_key(&block)
30
+ end
31
+
32
+ def self.encryption_key
33
+ ENV.fetch("ENCRYPTION_KEY", "thisisVeryUnsafe4U")
34
+ end
35
+
36
+ def self.encryption_key_fingerprint
37
+ base = RbNaCl::Hash.sha256(encryption_key)[0..15]
38
+ Base64.urlsafe_encode64(RbNaCl::Hash.sha256(base)[0..7])
39
+ end
40
+
24
41
  def self.key?(name)
25
42
  storage.key?(name)
26
43
  end
@@ -30,7 +47,11 @@ module Waylon
30
47
  raw = storage.load(key)
31
48
  return nil unless raw
32
49
 
33
- decoded = Base64.decode64(raw)
50
+ wrapper = JSON.parse(raw)
51
+ value = wrapper["data"]
52
+ return nil unless value
53
+
54
+ decoded = Base64.decode64(value)
34
55
  plain = this_cipher.decrypt(decoded)
35
56
  JSON.parse(plain)
36
57
  end
@@ -47,7 +68,8 @@ module Waylon
47
68
  this_cipher = cipher
48
69
  encrypted = this_cipher.encrypt(value.to_json)
49
70
  encoded = Base64.encode64(encrypted)
50
- storage.store(key, encoded)
71
+ wrapper = { cipher: cipher.class.name, data: encoded, key: encryption_key_fingerprint }
72
+ storage.store(key, wrapper.to_json)
51
73
  end
52
74
  end
53
75
  end
@@ -6,7 +6,7 @@ module Waylon
6
6
  VERSION = [
7
7
  0, # Major
8
8
  2, # Minor
9
- 3 # Patch
9
+ 6 # 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.6
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-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable