fernet 2.0 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efb5c9527493461aaaad3028cd173385ff0be58e
4
+ data.tar.gz: 7eff184a0653c03050f7b0e1a7e4886175450bb1
5
+ SHA512:
6
+ metadata.gz: 92c79ba58f03bd005fca1541787d38b8521aef2942063f0c34fc1444ecded93ba2c2ef72655be11520bc07638bc270d3d330813a2ff4342f5264b75b354be2e3
7
+ data.tar.gz: 6f2351ba928cc24591210c00eee201f374a36e51b66181772cff7340dfe7c7df02908312293a6d40670cbd2118945c46306750e45634fc617d22993a481abc7c
@@ -1,3 +1,4 @@
1
+ require 'fernet/errors'
1
2
  require 'fernet/version'
2
3
  require 'fernet/bit_packing'
3
4
  require 'fernet/encryption'
@@ -0,0 +1,3 @@
1
+ module Fernet
2
+ class Error < StandardError; end
3
+ end
@@ -1,10 +1,11 @@
1
1
  require 'base64'
2
+ require_relative 'errors'
2
3
 
3
4
  module Fernet
4
5
  # Internal: Encapsulates a secret key, a 32-byte sequence consisting
5
6
  # of an encryption and a signing key.
6
7
  class Secret
7
- class InvalidSecret < RuntimeError; end
8
+ class InvalidSecret < Fernet::Error; end
8
9
 
9
10
  # Internal - Initialize a Secret
10
11
  #
@@ -1,13 +1,14 @@
1
1
  # encoding UTF-8
2
2
  require 'base64'
3
3
  require 'valcro'
4
+ require_relative 'errors'
4
5
 
5
6
  module Fernet
6
7
  # Internal: encapsulates a fernet token structure and validation
7
8
  class Token
8
9
  include Valcro
9
10
 
10
- class InvalidToken < StandardError; end
11
+ class InvalidToken < Fernet::Error; end
11
12
 
12
13
  # Internal: the default token version
13
14
  DEFAULT_VERSION = 0x80.freeze
@@ -2,11 +2,12 @@
2
2
  require 'base64'
3
3
  require 'openssl'
4
4
  require 'date'
5
+ require_relative 'errors'
5
6
 
6
7
  module Fernet
7
8
  # Public: verifies Fernet Tokens
8
9
  class Verifier
9
- class UnknownTokenVersion < RuntimeError; end
10
+ class UnknownTokenVersion < Fernet::Error; end
10
11
 
11
12
  attr_reader :token
12
13
  attr_accessor :ttl, :enforce_ttl
@@ -42,7 +43,7 @@ module Fernet
42
43
 
43
44
  # Deprecated: returns the token's message
44
45
  def data
45
- puts "[WARNING] data is deprected. Use message instead"
46
+ puts "[WARNING] data is deprecated. Use message instead"
46
47
  message
47
48
  end
48
49
 
@@ -1,3 +1,3 @@
1
1
  module Fernet
2
- VERSION = "2.0"
2
+ VERSION = "2.1"
3
3
  end
@@ -19,7 +19,7 @@ describe Fernet do
19
19
  token = Fernet.generate(secret, 'harold@heroku.com')
20
20
 
21
21
  verifier = Fernet.verifier(bad_secret, token)
22
- expect(verifier.valid?).to be_false
22
+ expect(verifier.valid?).to eq(false)
23
23
  expect {
24
24
  verifier.message
25
25
  }.to raise_error Fernet::Token::InvalidToken
@@ -29,7 +29,7 @@ describe Fernet do
29
29
  token = Fernet.generate(secret, 'harold@heroku.com', now: (Time.now - 61))
30
30
 
31
31
  verifier = Fernet.verifier(secret, token)
32
- expect(verifier.valid?).to be_false
32
+ expect(verifier.valid?).to eq(false)
33
33
  end
34
34
 
35
35
  it 'can ignore TTL enforcement' do
@@ -41,7 +41,7 @@ describe Fernet do
41
41
 
42
42
  verifier = Fernet.verifier(secret, token, enforce_ttl: false,
43
43
  now: Time.now + 9999)
44
- expect(verifier.valid?).to be_true
44
+ expect(verifier.valid?).to eq(true)
45
45
  end
46
46
 
47
47
  it 'can ignore TTL enforcement via global config' do
@@ -52,7 +52,7 @@ describe Fernet do
52
52
  token = Fernet.generate(secret, 'harold@heroku.com')
53
53
 
54
54
  verifier = Fernet.verifier(secret, token, now: Time.now + 999999)
55
- expect(verifier.valid?).to be_true
55
+ expect(verifier.valid?).to eq(true)
56
56
  end
57
57
 
58
58
  it 'does not send the message in plain text' do
@@ -69,7 +69,7 @@ describe Fernet do
69
69
  token = Fernet.generate(secret, 'password1')
70
70
  verifier = Fernet.verifier(secret, token)
71
71
  verifier.enforce_ttl = false
72
- expect(verifier.valid?).to be_true
72
+ expect(verifier.valid?).to eq(true)
73
73
  expect(verifier.message).to eq('password1')
74
74
  end
75
75
  end
@@ -13,7 +13,7 @@ describe Fernet::Token, 'validation' do
13
13
 
14
14
  token = Fernet::Token.new(generated.to_s, secret: secret)
15
15
 
16
- expect(token.valid?).to be_false
16
+ expect(token.valid?).to eq(false)
17
17
  expect(token.errors[:signature]).to include("does not match")
18
18
  end
19
19
 
@@ -24,7 +24,7 @@ describe Fernet::Token, 'validation' do
24
24
  token = Fernet::Token.new(generated.to_s, enforce_ttl: true,
25
25
  ttl: 60,
26
26
  secret: secret)
27
- expect(token.valid?).to be_false
27
+ expect(token.valid?).to eq(false)
28
28
  expect(token.errors[:issued_timestamp]).to include("is too far in the past: token expired")
29
29
  end
30
30
 
@@ -34,21 +34,21 @@ describe Fernet::Token, 'validation' do
34
34
  now: Time.at(Time.now.to_i + 61))
35
35
  token = Fernet::Token.new(generated.to_s, secret: secret)
36
36
 
37
- expect(token.valid?).to be_false
37
+ expect(token.valid?).to eq(false)
38
38
  expect(token.errors[:issued_timestamp]).to include("is too far in the future")
39
39
  end
40
40
 
41
41
  it 'is invalid with bad base64' do
42
42
  token = Fernet::Token.new('bad', secret: secret)
43
43
 
44
- expect(token.valid?).to be_false
44
+ expect(token.valid?).to eq(false)
45
45
  expect(token.errors[:token]).to include("invalid base64")
46
46
  end
47
47
 
48
48
  it 'is invalid with an unknown token version' do
49
49
  token = Fernet::Token.new(Base64.urlsafe_encode64("xxxxxx"), secret: secret)
50
50
 
51
- expect(token.valid?).to be_false
51
+ expect(token.valid?).to eq(false)
52
52
  expect(token.errors[:version]).to include("is unknown")
53
53
  end
54
54
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fernet
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
5
- prerelease:
4
+ version: '2.1'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Harold Giménez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: valcro
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
@@ -30,17 +27,15 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Delicious HMAC Digest(if) authentication and AES-128-CBC encryption
@@ -50,11 +45,11 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - .gitignore
54
- - .gitmodules
55
- - .rdoc_options
56
- - .rspec
57
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".gitmodules"
50
+ - ".rdoc_options"
51
+ - ".rspec"
52
+ - ".travis.yml"
58
53
  - Gemfile
59
54
  - LICENSE
60
55
  - README.md
@@ -64,6 +59,7 @@ files:
64
59
  - lib/fernet/bit_packing.rb
65
60
  - lib/fernet/configuration.rb
66
61
  - lib/fernet/encryption.rb
62
+ - lib/fernet/errors.rb
67
63
  - lib/fernet/generator.rb
68
64
  - lib/fernet/secret.rb
69
65
  - lib/fernet/token.rb
@@ -78,27 +74,26 @@ files:
78
74
  - spec/token_spec.rb
79
75
  homepage: ''
80
76
  licenses: []
77
+ metadata: {}
81
78
  post_install_message:
82
79
  rdoc_options: []
83
80
  require_paths:
84
81
  - lib
85
82
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
83
  requirements:
88
- - - ! '>='
84
+ - - ">="
89
85
  - !ruby/object:Gem::Version
90
86
  version: '0'
91
87
  required_rubygems_version: !ruby/object:Gem::Requirement
92
- none: false
93
88
  requirements:
94
- - - ! '>='
89
+ - - ">="
95
90
  - !ruby/object:Gem::Version
96
91
  version: '0'
97
92
  requirements: []
98
93
  rubyforge_project:
99
- rubygems_version: 1.8.23
94
+ rubygems_version: 2.2.2
100
95
  signing_key:
101
- specification_version: 3
96
+ specification_version: 4
102
97
  summary: Easily generate and verify AES encrypted HMAC based authentication tokens
103
98
  test_files:
104
99
  - spec/acceptance/generate_spec.rb