cryptatron 0.0.2 → 0.0.3

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.
@@ -3,11 +3,9 @@ require 'yaml'
3
3
  require 'gibberish'
4
4
 
5
5
  module Cryptatron
6
- settings = YAML::load_file "#{Rails.root}/config/crypt-a-tron.yml"
7
- @key = Base64.strict_decode64 settings['key']
8
- @cipher = Gibberish::AES.new(@key, @key.length)
9
-
10
6
  def self.encrypt(body)
7
+ setup
8
+
11
9
  begin
12
10
  Base64.strict_encode64 @cipher.encrypt(body, binary: true)
13
11
  rescue
@@ -16,10 +14,26 @@ module Cryptatron
16
14
  end
17
15
 
18
16
  def self.decrypt(body)
17
+ setup
18
+
19
19
  begin
20
20
  @cipher.decrypt(body)
21
21
  rescue
22
22
  nil
23
23
  end
24
24
  end
25
+
26
+ private
27
+
28
+ @initialized = false
29
+
30
+ def self.setup
31
+ return if @initialized
32
+
33
+ settings = YAML::load_file "#{Rails.root}/config/crypt-a-tron.yml"
34
+ @key = Base64.strict_decode64 settings['key']
35
+ @cipher = Gibberish::AES.new(@key, @key.length)
36
+
37
+ @initialized = true
38
+ end
25
39
  end
@@ -1,3 +1,3 @@
1
1
  module Cryptatron
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gibberish