fernet 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,14 @@ require 'fernet/version'
2
2
  require 'fernet/generator'
3
3
  require 'fernet/verifier'
4
4
  require 'fernet/secret'
5
+ require 'fernet/configuration'
5
6
 
6
7
  if RUBY_VERSION == '1.8.7'
7
8
  require 'shim/base64'
8
9
  end
9
10
 
11
+ Fernet::Configuration.run
12
+
10
13
  module Fernet
11
14
  def self.generate(secret, encrypt = true, &block)
12
15
  Generator.new(secret, encrypt).generate(&block)
@@ -0,0 +1,34 @@
1
+ require 'singleton'
2
+ module Fernet
3
+ class Configuration
4
+ include Singleton
5
+
6
+ # Whether to enforce a message TTL
7
+ # (true or false)
8
+ attr_accessor :enforce_ttl
9
+
10
+ # How long messages are considered valid to the verifier
11
+ # (an integer in seconds)
12
+ attr_accessor :ttl
13
+
14
+ def self.run
15
+ self.instance.enforce_ttl = true
16
+ self.instance.ttl = 60
17
+ yield self.instance if block_given?
18
+ end
19
+
20
+ class << self
21
+ def method_missing(method)
22
+ if self.instance.respond_to?(method)
23
+ self.instance.send(method)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ def respond_to?(method)
30
+ self.instance.respond_to?(method) || super
31
+ end
32
+ end
33
+ end
34
+ end
@@ -11,8 +11,8 @@ module Fernet
11
11
  def initialize(secret, decrypt)
12
12
  @secret = Secret.new(secret, decrypt)
13
13
  @decrypt = decrypt
14
- @ttl = 60
15
- @enforce_ttl = true
14
+ @ttl = Configuration.ttl
15
+ @enforce_ttl = Configuration.enforce_ttl
16
16
  end
17
17
 
18
18
  def verify_token(token)
@@ -1,3 +1,3 @@
1
1
  module Fernet
2
- VERSION = "1.1"
2
+ VERSION = "1.2"
3
3
  end
@@ -57,7 +57,7 @@ describe Fernet do
57
57
  Fernet.verify(secret, token).should be_true
58
58
  end
59
59
 
60
- it 'can TTL enforcement' do
60
+ it 'can ignore TTL enforcement' do
61
61
  token = Fernet.generate(secret) do |generator|
62
62
  generator.data = token_data
63
63
  end
@@ -71,6 +71,23 @@ describe Fernet do
71
71
  end.should be_true
72
72
  end
73
73
 
74
+ it 'can ignore TTL enforcement via global config' do
75
+ Fernet::Configuration.run do |config|
76
+ config.enforce_ttl = false
77
+ end
78
+
79
+ token = Fernet.generate(secret) do |generator|
80
+ generator.data = token_data
81
+ end
82
+
83
+ Fernet.verify(secret, token) do |verifier|
84
+ def verifier.now
85
+ Time.now + 99999999999
86
+ end
87
+ true
88
+ end.should be_true
89
+ end
90
+
74
91
  it 'generates without custom data' do
75
92
  token = Fernet.generate(secret)
76
93
 
metadata CHANGED
@@ -1,59 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fernet
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.2'
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- version: "1.1"
10
6
  platform: ruby
11
- authors:
12
- - "Harold Gim\xC3\xA9nez"
7
+ authors:
8
+ - Harold Giménez
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-08-15 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: yajl-ruby
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70181117517580 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70181117517580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70181117517160 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
45
33
  type: :development
46
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *70181117517160
47
36
  description: Delicious HMAC Digest(if) authentication and encryption
48
- email:
37
+ email:
49
38
  - harold.gimenez@gmail.com
50
39
  executables: []
51
-
52
40
  extensions: []
53
-
54
41
  extra_rdoc_files: []
55
-
56
- files:
42
+ files:
57
43
  - .gitignore
58
44
  - .rspec
59
45
  - Gemfile
@@ -62,6 +48,7 @@ files:
62
48
  - Rakefile
63
49
  - fernet.gemspec
64
50
  - lib/fernet.rb
51
+ - lib/fernet/configuration.rb
65
52
  - lib/fernet/generator.rb
66
53
  - lib/fernet/secret.rb
67
54
  - lib/fernet/verifier.rb
@@ -69,39 +56,30 @@ files:
69
56
  - lib/shim/base64.rb
70
57
  - spec/fernet_spec.rb
71
58
  - spec/spec_helper.rb
72
- homepage: ""
59
+ homepage: ''
73
60
  licenses: []
74
-
75
61
  post_install_message:
76
62
  rdoc_options: []
77
-
78
- require_paths:
63
+ require_paths:
79
64
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
81
66
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
72
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- hash: 3
95
- segments:
96
- - 0
97
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
98
77
  requirements: []
99
-
100
78
  rubyforge_project:
101
79
  rubygems_version: 1.8.10
102
80
  signing_key:
103
81
  specification_version: 3
104
82
  summary: Easily generate and verify AES encrypted HMAC based authentication tokens
105
- test_files:
83
+ test_files:
106
84
  - spec/fernet_spec.rb
107
85
  - spec/spec_helper.rb