tokenifier 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,6 @@ module Tokenifier
19
19
 
20
20
  filename = Rails.root.join('config', 'tokenifier.yml')
21
21
 
22
- puts filename
23
-
24
22
  if File.exists?(filename)
25
23
  config = YAML.load(
26
24
  ERB.new(
@@ -3,8 +3,8 @@ module Tokenifier
3
3
 
4
4
  # data marshaling differs depending to ruby version
5
5
  # so its better to pack hash into string accoring to some rule
6
- def pack_hash(hsh)
7
- hsh.map { |v| v.join(':') }.join('#')
6
+ def pack_hash(hsh, delimeter = '#')
7
+ hsh.map { |v| v.join(':') }.join(delimeter)
8
8
  end
9
9
 
10
10
  def encrypt(data, options = {})
@@ -13,9 +13,13 @@ module Tokenifier
13
13
  raise Tokenifier::Error, "DATA should not be empty" if data.respond_to?(:empty?) && data.empty?
14
14
 
15
15
  cipher(options[:secret]) do |c|
16
- c.enc(data.is_a?(Hash) ? pack_hash(data) : data.to_s)
16
+ c.enc(data.is_a?(Hash) ? pack_hash(data) : data.to_s).gsub(/\n/, '')
17
17
  end
18
+ end
18
19
 
20
+ def key(data = {})
21
+ delimeter = data[:delimeter] || "##"
22
+ Gibberish::SHA256(pack_hash(data, delimeter))
19
23
  end
20
24
 
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module Tokenifier
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/spec/encrypt_spec.rb CHANGED
@@ -76,4 +76,22 @@ describe Tokenifier::Encrypt do
76
76
 
77
77
  end
78
78
 
79
+ describe ".key" do
80
+ context "should be symetric" do
81
+ let(:first) { subject.key(:username => 'test', :password => 'test', :salt => 'aaaabbbb') }
82
+ let(:second) { subject.key(:username => 'test', :password => 'test', :salt => 'aaaabbbb') }
83
+
84
+ specify { first.should == second }
85
+ specify { second.should == first }
86
+ end
87
+
88
+ context "should use delimeter" do
89
+ let(:first) { subject.key(:username => 'test', :password => 'test', :delimeter => '$') }
90
+ let(:second) { subject.key(:username => 'test', :password => 'test', :delimeter => '#') }
91
+
92
+ specify { first.should_not == second }
93
+ specify { second.should_not == first }
94
+ end
95
+ end
96
+
79
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokenifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gibberish
16
- requirement: &70275141515140 !ruby/object:Gem::Requirement
16
+ requirement: &70292001665000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70275141515140
24
+ version_requirements: *70292001665000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70275141514640 !ruby/object:Gem::Requirement
27
+ requirement: &70292001664500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70275141514640
35
+ version_requirements: *70292001664500
36
36
  description: Tokenifier is a Gibberish gem wrapper. It provides an aproach to encrypt
37
37
  and decrypt structures like Strings, Hashes.
38
38
  email: