obfuscate 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/lib/obfuscate/crypt.rb +2 -2
- data/lib/obfuscate/obfuscatable.rb +1 -1
- data/lib/obfuscate/version.rb +1 -1
- data/spec/lib/obfuscate/crypt_spec.rb +4 -2
- data/spec/lib/obfuscate/ofuscatable_spec.rb +4 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -28,8 +28,8 @@ A simple example
|
|
28
28
|
config.mode = :string # defaults to :string
|
29
29
|
end
|
30
30
|
|
31
|
-
obfuscated = Obfuscate.obfuscate( "test" )
|
32
|
-
clarified = Obfuscate.clarify( obfuscated )
|
31
|
+
obfuscated = Obfuscate.obfuscate( "test" ) # "HoDruKtafqyLxZxu9s-kYQ=="
|
32
|
+
clarified = Obfuscate.clarify( obfuscated ) # "test"
|
33
33
|
|
34
34
|
## Rails Integration
|
35
35
|
|
@@ -49,15 +49,15 @@ Now add to models that you want to be `Obfuscatable`:
|
|
49
49
|
To get the 11 character `obfuscated_id`, which uses `mode :block` for the Blowfish single block encryption:
|
50
50
|
|
51
51
|
message = Message.find(1)
|
52
|
-
obfuscated = message.obfuscated_id
|
53
|
-
clarified = message.clarify_id( obfuscated )
|
52
|
+
obfuscated = message.obfuscated_id # "NuwhZTtHnko"
|
53
|
+
clarified = message.clarify_id( obfuscated ) # "1"
|
54
54
|
|
55
55
|
Message.find_by_obfuscated_id( obfuscated )
|
56
56
|
|
57
57
|
Or `obfuscate` a block of text, defaults to mode :string which uses Blowfish string encryption, allowing longer
|
58
58
|
blocks of text to be obfuscated.
|
59
59
|
|
60
|
-
obfuscated = message.obfuscate( "if you use your imagination, this is a long block of text" )
|
60
|
+
obfuscated = message.obfuscate( "if you use your imagination, this is a long block of text" ) # "GoxjVCCuBQgaLvttm7mXNEN9U6A_xxBjM3CYWBrsWs640PVXmkuypo7S8rBHEv_z1jP3hhFqQzlI9L1s2DTQ6FYZwfop-xlA"
|
61
61
|
clarified = message.clarify( obfuscated )
|
62
62
|
|
63
63
|
|
data/lib/obfuscate/crypt.rb
CHANGED
@@ -48,7 +48,7 @@ class Obfuscate::Crypt
|
|
48
48
|
end
|
49
49
|
|
50
50
|
if @exec_config.encode
|
51
|
-
obfuscated =
|
51
|
+
obfuscated = Base64.urlsafe_encode64(obfuscated).strip
|
52
52
|
obfuscated = obfuscated.chomp("=") if @exec_config.remove_trailing_equal?
|
53
53
|
end
|
54
54
|
|
@@ -67,7 +67,7 @@ class Obfuscate::Crypt
|
|
67
67
|
|
68
68
|
if @exec_config.encode
|
69
69
|
obfuscated << "=" if @exec_config.remove_trailing_equal?
|
70
|
-
obfuscated = Base64.
|
70
|
+
obfuscated = Base64.urlsafe_decode64( obfuscated )
|
71
71
|
end
|
72
72
|
|
73
73
|
if @exec_config.mode == :string
|
data/lib/obfuscate/version.rb
CHANGED
@@ -22,7 +22,7 @@ describe Obfuscate::Crypt do
|
|
22
22
|
|
23
23
|
describe "obfuscate block mode" do
|
24
24
|
before(:each) do
|
25
|
-
@config = Obfuscate.
|
25
|
+
@config = Obfuscate::Config.new.tap do |config|
|
26
26
|
config.salt = "salt-salt-salt"
|
27
27
|
config.mode = :block
|
28
28
|
end
|
@@ -39,7 +39,9 @@ describe Obfuscate::Crypt do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should obfuscate without encoding" do
|
42
|
+
@config.encode.should be_true
|
42
43
|
crypt = Obfuscate::Crypt.new( @config.apply(:encode => false ) )
|
44
|
+
@config.encode.should be_true
|
43
45
|
crypt.obfuscate("without encoding").should eql "\x8F\xC7\xE4\n,2\xA2\xA7"
|
44
46
|
end
|
45
47
|
|
@@ -51,7 +53,7 @@ describe Obfuscate::Crypt do
|
|
51
53
|
|
52
54
|
describe "obfuscate string mode" do
|
53
55
|
before(:each) do
|
54
|
-
@config = Obfuscate.
|
56
|
+
@config = Obfuscate::Config.new.tap do |config|
|
55
57
|
config.salt = "salt-salt-salt"
|
56
58
|
config.mode = :string
|
57
59
|
end
|
@@ -45,16 +45,16 @@ describe Obfuscate::Obfuscatable do
|
|
45
45
|
model
|
46
46
|
end
|
47
47
|
|
48
|
-
it "should
|
49
|
-
model.
|
48
|
+
it "should obfuscated id" do
|
49
|
+
model.obfuscated_id.should_not be nil
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should clarify id" do
|
53
|
-
model.clarify_id( model.
|
53
|
+
model.clarify_id( model.obfuscated_id ).to_i.should eql model.id
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should find_by_obfuscated_id" do
|
57
|
-
Message.find_by_obfuscated_id( model.
|
57
|
+
Message.find_by_obfuscated_id( model.obfuscated_id ).should eql model
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obfuscate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
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-02-
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: crypt19
|