encrypt_env 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/encrypt_env.rb +9 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27c78b9777eaf2d1de712e3e14e0eb69aeaeb4126c658831e093fd3d009a74e1
4
- data.tar.gz: 602f65454d578bedeb4afcb7cab5e8bdd15fec83804a7ca638e31eceba512aba
3
+ metadata.gz: e35036de05df44f35b795a71ce0ed572b0f2dcfc44feb4a698dfe8bee1297f99
4
+ data.tar.gz: 04dedad57df86333120ba5a7ce89fc9cdcb4aef4b4766bc34dc102aeb3ce2329
5
5
  SHA512:
6
- metadata.gz: 51bbe5039a0e27aaad62b0504cf9ae9a316ffd0e4c33e02b4559541901fe9691cc077a9e4a304e42ac90fe146747a66cdd221a5b97c02dd283a92065f23063d8
7
- data.tar.gz: b84ca2e78d722954cd6f67614d6290101c0688856497086bbd091cfce6424d7baa6f426464682a5ffbbd1cae1edba262756e698aa8bd5f7bc48a30d8e3989fcf
6
+ metadata.gz: 4a6dd9844f93379572d3ba096f0e1d598a86ae194bb9442084e6cd989c76df1a533cfbd2921ba1128d683ac0a92b10fe8cb0561f8baa4271720a8a25946fb9fe
7
+ data.tar.gz: 6ba4369b23622f34a45d287d9834bf514ff6f86e9f416adc9a8a9e12840a7dbfe5bb4a27dadb579c2f4f5ffc48b99a82017f4e2881929a1be2b99e6cf4c92674
data/lib/encrypt_env.rb CHANGED
@@ -7,7 +7,6 @@ require 'active_support/core_ext/hash/indifferent_access'
7
7
  require 'tempfile'
8
8
 
9
9
  # gem 'encrypt_env'
10
- # rubocop: disable all
11
10
  class EncryptEnv
12
11
  private_class_method def self.master_key
13
12
  key = File.read("#{@path_root}/config/master.key")
@@ -18,7 +17,7 @@ class EncryptEnv
18
17
  encrypted = raw_data.slice(0, raw_data.length - 28)
19
18
  iv = raw_data.slice(raw_data.length - 28, 12)
20
19
  tag = raw_data.slice(raw_data.length - 16, 16)
21
- return { encrypted: encrypted, iv: iv, tag: tag }
20
+ { encrypted: encrypted, iv: iv, tag: tag }
22
21
  end
23
22
 
24
23
  private_class_method def self.encrypt(content)
@@ -26,9 +25,10 @@ class EncryptEnv
26
25
  cipher.encrypt
27
26
  cipher.key = master_key
28
27
  iv = cipher.random_iv
28
+ cipher.auth_data = ''
29
29
  encrypted = cipher.update(content) + cipher.final
30
30
  tag = cipher.auth_tag
31
- hex_string = (encrypted + iv + tag).unpack('H*').first
31
+ hex_string = (encrypted + iv + tag).unpack('H*')[0]
32
32
  File.open("#{@path_root}/config/secrets.yml.enc", 'w') { |file| file.write(hex_string) }
33
33
  end
34
34
 
@@ -37,11 +37,13 @@ class EncryptEnv
37
37
  decipher.decrypt
38
38
  hex_string = File.read("#{@path_root}/config/secrets.yml.enc")
39
39
  data = data_decrypt([hex_string].pack('H*'))
40
- decipher.iv = data[:iv]
40
+ encrypted = data[:encrypted]
41
41
  decipher.key = master_key
42
+ decipher.iv = data[:iv]
42
43
  decipher.auth_tag = data[:tag]
44
+ decipher.auth_data = ''
43
45
 
44
- decipher.update(data[:encrypted]) + decipher.final
46
+ decipher.update(encrypted) + decipher.final
45
47
  end
46
48
 
47
49
  private_class_method def self.path_root
@@ -59,7 +61,7 @@ class EncryptEnv
59
61
  @secret_file = File.expand_path("#{@path_root}/config/secrets.yml")
60
62
  key = OpenSSL::Random.random_bytes(16)
61
63
  # save key in master.key file
62
- File.open("#{@path_root}/config/master.key", 'w') { |file| file.write(key.unpack('H*').first) }
64
+ File.open("#{@path_root}/config/master.key", 'w') { |file| file.write(key.unpack('H*')[0]) }
63
65
  encrypt(File.read(@secret_file))
64
66
  end
65
67
 
@@ -86,9 +88,7 @@ class EncryptEnv
86
88
  return @decrypted if @decrypted
87
89
 
88
90
  path_root unless @path_root
89
- @decrypted = HashWithIndifferentAccess.new(YAML.safe_load(
90
- decrypt, aliases: true
91
- ))
91
+ @decrypted = HashWithIndifferentAccess.new(YAML.load(decrypt, aliases: true))
92
92
  unless defined?(Rails)
93
93
  env = `rails r "print Rails.env"`.to_sym
94
94
  return @decrypted[env] || @decrypted[:default] || @decrypted
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypt_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhu Tan