fernet 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/fernet.rb +3 -3
- data/lib/fernet/configuration.rb +5 -0
- data/lib/fernet/version.rb +1 -1
- data/spec/fernet_spec.rb +16 -0
- metadata +5 -5
data/README.md
CHANGED
@@ -58,6 +58,19 @@ The specs
|
|
58
58
|
([spec/fernet_spec.rb](https://github.com/hgmnz/fernet/blob/master/spec/fernet_spec.rb))
|
59
59
|
have more usage examples.
|
60
60
|
|
61
|
+
### Global configuration
|
62
|
+
|
63
|
+
It's possible to configure fernet via the `Configuration` class. Put this in an initializer:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# default values shown here
|
67
|
+
Fernet::Configuration.run do |config|
|
68
|
+
config.enforce_ttl = true
|
69
|
+
config.ttl = 60
|
70
|
+
config.encrypt = true
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
61
74
|
### Generating a secret
|
62
75
|
|
63
76
|
Generating appropriate secrets is beyond the scope of `Fernet`, but you should
|
data/lib/fernet.rb
CHANGED
@@ -11,11 +11,11 @@ end
|
|
11
11
|
Fernet::Configuration.run
|
12
12
|
|
13
13
|
module Fernet
|
14
|
-
def self.generate(secret, encrypt =
|
14
|
+
def self.generate(secret, encrypt = Configuration.encrypt, &block)
|
15
15
|
Generator.new(secret, encrypt).generate(&block)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.verify(secret, token,
|
19
|
-
Verifier.new(secret,
|
18
|
+
def self.verify(secret, token, encrypt = Configuration.encrypt, &block)
|
19
|
+
Verifier.new(secret, encrypt).verify_token(token, &block)
|
20
20
|
end
|
21
21
|
end
|
data/lib/fernet/configuration.rb
CHANGED
@@ -11,9 +11,14 @@ module Fernet
|
|
11
11
|
# (an integer in seconds)
|
12
12
|
attr_accessor :ttl
|
13
13
|
|
14
|
+
# Whether to encrypt the payload
|
15
|
+
# (true or false)
|
16
|
+
attr_accessor :encrypt
|
17
|
+
|
14
18
|
def self.run
|
15
19
|
self.instance.enforce_ttl = true
|
16
20
|
self.instance.ttl = 60
|
21
|
+
self.instance.encrypt = true
|
17
22
|
yield self.instance if block_given?
|
18
23
|
end
|
19
24
|
|
data/lib/fernet/version.rb
CHANGED
data/spec/fernet_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'fernet'
|
3
3
|
|
4
4
|
describe Fernet do
|
5
|
+
after { Fernet::Configuration.run }
|
6
|
+
|
5
7
|
let(:token_data) do
|
6
8
|
{ :email => 'harold@heroku.com', :id => '123', :arbitrary => 'data' }
|
7
9
|
end
|
@@ -119,4 +121,18 @@ describe Fernet do
|
|
119
121
|
verifier.data['password'].should == 'password1'
|
120
122
|
end
|
121
123
|
end
|
124
|
+
|
125
|
+
it 'can disable encryption via global configuration' do
|
126
|
+
Fernet::Configuration.run { |c| c.encrypt = false }
|
127
|
+
token = Fernet.generate(secret) do |generator|
|
128
|
+
generator.data['password'] = 'password1'
|
129
|
+
end
|
130
|
+
|
131
|
+
payload = Base64.decode64(token)
|
132
|
+
payload.should match /password1/
|
133
|
+
|
134
|
+
Fernet.verify(secret, token) do |verifier|
|
135
|
+
verifier.data['password'].should == 'password1'
|
136
|
+
end
|
137
|
+
end
|
122
138
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fernet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70208527724740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70208527724740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70208527724320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70208527724320
|
36
36
|
description: Delicious HMAC Digest(if) authentication and encryption
|
37
37
|
email:
|
38
38
|
- harold.gimenez@gmail.com
|