jwt 2.3.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +60 -53
  3. data/CHANGELOG.md +82 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/CONTRIBUTING.md +99 -0
  6. data/README.md +188 -40
  7. data/lib/jwt/algos/algo_wrapper.rb +26 -0
  8. data/lib/jwt/algos/ecdsa.rb +55 -14
  9. data/lib/jwt/algos/eddsa.rb +7 -4
  10. data/lib/jwt/algos/hmac.rb +56 -17
  11. data/lib/jwt/algos/hmac_rbnacl.rb +53 -0
  12. data/lib/jwt/algos/hmac_rbnacl_fixed.rb +52 -0
  13. data/lib/jwt/algos/none.rb +5 -1
  14. data/lib/jwt/algos/ps.rb +10 -12
  15. data/lib/jwt/algos/rsa.rb +9 -5
  16. data/lib/jwt/algos/unsupported.rb +2 -0
  17. data/lib/jwt/algos.rb +37 -15
  18. data/lib/jwt/claims_validator.rb +3 -1
  19. data/lib/jwt/configuration/container.rb +21 -0
  20. data/lib/jwt/configuration/decode_configuration.rb +46 -0
  21. data/lib/jwt/configuration/jwk_configuration.rb +27 -0
  22. data/lib/jwt/configuration.rb +15 -0
  23. data/lib/jwt/decode.rb +83 -26
  24. data/lib/jwt/encode.rb +30 -20
  25. data/lib/jwt/error.rb +1 -0
  26. data/lib/jwt/jwk/ec.rb +147 -61
  27. data/lib/jwt/jwk/hmac.rb +69 -24
  28. data/lib/jwt/jwk/key_base.rb +43 -6
  29. data/lib/jwt/jwk/key_finder.rb +19 -35
  30. data/lib/jwt/jwk/kid_as_key_digest.rb +15 -0
  31. data/lib/jwt/jwk/okp_rbnacl.rb +110 -0
  32. data/lib/jwt/jwk/rsa.rb +142 -54
  33. data/lib/jwt/jwk/set.rb +80 -0
  34. data/lib/jwt/jwk/thumbprint.rb +26 -0
  35. data/lib/jwt/jwk.rb +15 -11
  36. data/lib/jwt/verify.rb +10 -2
  37. data/lib/jwt/version.rb +23 -3
  38. data/lib/jwt/x5c_key_finder.rb +55 -0
  39. data/lib/jwt.rb +5 -4
  40. data/ruby-jwt.gemspec +12 -5
  41. metadata +20 -17
  42. data/.github/workflows/test.yml +0 -74
  43. data/.gitignore +0 -11
  44. data/.rspec +0 -2
  45. data/.rubocop.yml +0 -97
  46. data/.rubocop_todo.yml +0 -185
  47. data/.sourcelevel.yml +0 -18
  48. data/Appraisals +0 -10
  49. data/Gemfile +0 -5
  50. data/Rakefile +0 -14
  51. data/lib/jwt/default_options.rb +0 -16
  52. data/lib/jwt/security_utils.rb +0 -57
  53. data/lib/jwt/signature.rb +0 -39
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rudat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-03 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -87,32 +87,31 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".github/workflows/test.yml"
91
- - ".gitignore"
92
- - ".rspec"
93
- - ".rubocop.yml"
94
- - ".rubocop_todo.yml"
95
- - ".sourcelevel.yml"
96
90
  - AUTHORS
97
- - Appraisals
98
91
  - CHANGELOG.md
99
- - Gemfile
92
+ - CODE_OF_CONDUCT.md
93
+ - CONTRIBUTING.md
100
94
  - LICENSE
101
95
  - README.md
102
- - Rakefile
103
96
  - lib/jwt.rb
104
97
  - lib/jwt/algos.rb
98
+ - lib/jwt/algos/algo_wrapper.rb
105
99
  - lib/jwt/algos/ecdsa.rb
106
100
  - lib/jwt/algos/eddsa.rb
107
101
  - lib/jwt/algos/hmac.rb
102
+ - lib/jwt/algos/hmac_rbnacl.rb
103
+ - lib/jwt/algos/hmac_rbnacl_fixed.rb
108
104
  - lib/jwt/algos/none.rb
109
105
  - lib/jwt/algos/ps.rb
110
106
  - lib/jwt/algos/rsa.rb
111
107
  - lib/jwt/algos/unsupported.rb
112
108
  - lib/jwt/base64.rb
113
109
  - lib/jwt/claims_validator.rb
110
+ - lib/jwt/configuration.rb
111
+ - lib/jwt/configuration/container.rb
112
+ - lib/jwt/configuration/decode_configuration.rb
113
+ - lib/jwt/configuration/jwk_configuration.rb
114
114
  - lib/jwt/decode.rb
115
- - lib/jwt/default_options.rb
116
115
  - lib/jwt/encode.rb
117
116
  - lib/jwt/error.rb
118
117
  - lib/jwt/json.rb
@@ -121,18 +120,22 @@ files:
121
120
  - lib/jwt/jwk/hmac.rb
122
121
  - lib/jwt/jwk/key_base.rb
123
122
  - lib/jwt/jwk/key_finder.rb
123
+ - lib/jwt/jwk/kid_as_key_digest.rb
124
+ - lib/jwt/jwk/okp_rbnacl.rb
124
125
  - lib/jwt/jwk/rsa.rb
125
- - lib/jwt/security_utils.rb
126
- - lib/jwt/signature.rb
126
+ - lib/jwt/jwk/set.rb
127
+ - lib/jwt/jwk/thumbprint.rb
127
128
  - lib/jwt/verify.rb
128
129
  - lib/jwt/version.rb
130
+ - lib/jwt/x5c_key_finder.rb
129
131
  - ruby-jwt.gemspec
130
132
  homepage: https://github.com/jwt/ruby-jwt
131
133
  licenses:
132
134
  - MIT
133
135
  metadata:
134
136
  bug_tracker_uri: https://github.com/jwt/ruby-jwt/issues
135
- changelog_uri: https://github.com/jwt/ruby-jwt/blob/v2.3.0/CHANGELOG.md
137
+ changelog_uri: https://github.com/jwt/ruby-jwt/blob/v2.7.1/CHANGELOG.md
138
+ rubygems_mfa_required: 'true'
136
139
  post_install_message:
137
140
  rdoc_options: []
138
141
  require_paths:
@@ -141,14 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
144
  requirements:
142
145
  - - ">="
143
146
  - !ruby/object:Gem::Version
144
- version: '2.1'
147
+ version: '2.5'
145
148
  required_rubygems_version: !ruby/object:Gem::Requirement
146
149
  requirements:
147
150
  - - ">="
148
151
  - !ruby/object:Gem::Version
149
152
  version: '0'
150
153
  requirements: []
151
- rubygems_version: 3.2.19
154
+ rubygems_version: 3.3.7
152
155
  signing_key:
153
156
  specification_version: 4
154
157
  summary: JSON Web Token implementation in Ruby
@@ -1,74 +0,0 @@
1
- ---
2
- name: test
3
- on:
4
- push:
5
- branches:
6
- - "*"
7
- pull_request:
8
- branches:
9
- - "*"
10
- jobs:
11
- lint:
12
- name: RuboCop
13
- timeout-minutes: 30
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@v2
17
- - name: Set up Ruby
18
- uses: ruby/setup-ruby@v1
19
- with:
20
- ruby-version: "2.4"
21
- bundler-cache: true
22
- - name: Run RuboCop
23
- run: bundle exec rubocop
24
- test:
25
- strategy:
26
- fail-fast: false
27
- matrix:
28
- ruby:
29
- - 2.3
30
- - 2.4
31
- - 2.5
32
- - 2.6
33
- - 2.7
34
- - "3.0"
35
- gemfile:
36
- - gemfiles/standalone.gemfile
37
- - gemfiles/openssl.gemfile
38
- - gemfiles/rbnacl.gemfile
39
- experimental: [false]
40
- include:
41
- - ruby: 2.1
42
- gemfile: 'gemfiles/rbnacl.gemfile'
43
- experimental: false
44
- - ruby: 2.2
45
- gemfile: 'gemfiles/rbnacl.gemfile'
46
- experimental: false
47
- - ruby: 2.7
48
- coverage: "true"
49
- gemfile: 'gemfiles/rbnacl.gemfile'
50
- - ruby: "ruby-head"
51
- experimental: true
52
- - ruby: "truffleruby-head"
53
- experimental: true
54
- runs-on: ubuntu-20.04
55
- continue-on-error: ${{ matrix.experimental }}
56
- env:
57
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
58
-
59
- steps:
60
- - uses: actions/checkout@v2
61
-
62
- - name: Install libsodium
63
- run: |
64
- sudo apt-get update -q
65
- sudo apt-get install libsodium-dev -y
66
-
67
- - name: Set up Ruby
68
- uses: ruby/setup-ruby@v1
69
- with:
70
- ruby-version: ${{ matrix.ruby }}
71
- bundler-cache: true
72
-
73
- - name: Run tests
74
- run: bundle exec rspec
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- .idea/
2
- jwt.gemspec
3
- pkg
4
- Gemfile.lock
5
- coverage/
6
- .DS_Store
7
- .rbenv-gemsets
8
- .ruby-version
9
- .vscode/
10
- .bundle
11
- *gemfile.lock
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --require spec_helper
2
- --color
data/.rubocop.yml DELETED
@@ -1,97 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- AllCops:
4
- TargetRubyVersion: 2.1
5
-
6
- Layout/AlignParameters:
7
- EnforcedStyle: with_fixed_indentation
8
-
9
- Layout/CaseIndentation:
10
- EnforcedStyle: end
11
-
12
- Style/AsciiComments:
13
- Enabled: false
14
-
15
- Layout/IndentHash:
16
- Enabled: false
17
-
18
- Style/CollectionMethods:
19
- Enabled: true
20
- PreferredMethods:
21
- inject: 'inject'
22
-
23
- Style/Documentation:
24
- Enabled: false
25
-
26
- Style/BlockDelimiters:
27
- Exclude:
28
- - spec/**/*_spec.rb
29
-
30
- Style/BracesAroundHashParameters:
31
- Exclude:
32
- - spec/**/*_spec.rb
33
-
34
- Style/GuardClause:
35
- Enabled: false
36
-
37
- Style/IfUnlessModifier:
38
- Enabled: false
39
-
40
- Layout/SpaceInsideHashLiteralBraces:
41
- Enabled: false
42
-
43
- Style/Lambda:
44
- Enabled: false
45
-
46
- Style/RaiseArgs:
47
- Enabled: false
48
-
49
- Style/SignalException:
50
- Enabled: false
51
-
52
- Metrics/AbcSize:
53
- Max: 20
54
-
55
- Metrics/ClassLength:
56
- Max: 101
57
-
58
- Metrics/ModuleLength:
59
- Max: 100
60
-
61
- Metrics/LineLength:
62
- Enabled: false
63
-
64
- Metrics/BlockLength:
65
- Exclude:
66
- - spec/**/*_spec.rb
67
-
68
- Metrics/MethodLength:
69
- Max: 15
70
-
71
- Style/SingleLineBlockParams:
72
- Enabled: false
73
-
74
- Lint/EndAlignment:
75
- EnforcedStyleAlignWith: variable
76
-
77
- Style/FormatString:
78
- Enabled: false
79
-
80
- Layout/MultilineMethodCallIndentation:
81
- EnforcedStyle: indented
82
-
83
- Layout/MultilineOperationIndentation:
84
- EnforcedStyle: indented
85
-
86
- Style/WordArray:
87
- Enabled: false
88
-
89
- Style/RedundantSelf:
90
- Enabled: false
91
-
92
- Layout/AlignHash:
93
- Enabled: true
94
- EnforcedLastArgumentHashStyle: always_ignore
95
-
96
- Style/TrivialAccessors:
97
- AllowPredicates: true
data/.rubocop_todo.yml DELETED
@@ -1,185 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2020-12-21 23:11:43 +0200 using RuboCop version 0.52.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 2
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
12
- # Include: **/*.gemspec
13
- Gemspec/OrderedDependencies:
14
- Exclude:
15
- - 'ruby-jwt.gemspec'
16
-
17
- # Offense count: 1
18
- # Cop supports --auto-correct.
19
- Layout/EmptyLines:
20
- Exclude:
21
- - 'spec/integration/readme_examples_spec.rb'
22
-
23
- # Offense count: 1
24
- # Cop supports --auto-correct.
25
- # Configuration parameters: EnforcedStyle.
26
- # SupportedStyles: empty_lines, no_empty_lines
27
- Layout/EmptyLinesAroundBlockBody:
28
- Exclude:
29
- - 'spec/jwt_spec.rb'
30
-
31
- # Offense count: 1
32
- # Cop supports --auto-correct.
33
- # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
34
- Layout/ExtraSpacing:
35
- Exclude:
36
- - 'spec/jwk_spec.rb'
37
-
38
- # Offense count: 2
39
- # Cop supports --auto-correct.
40
- # Configuration parameters: EnforcedStyle.
41
- # SupportedStyles: normal, rails
42
- Layout/IndentationConsistency:
43
- Exclude:
44
- - 'spec/jwt_spec.rb'
45
-
46
- # Offense count: 1
47
- # Cop supports --auto-correct.
48
- # Configuration parameters: Width, IgnoredPatterns.
49
- Layout/IndentationWidth:
50
- Exclude:
51
- - 'spec/jwt_spec.rb'
52
-
53
- # Offense count: 3
54
- # Cop supports --auto-correct.
55
- Layout/SpaceAfterComma:
56
- Exclude:
57
- - 'spec/jwt_spec.rb'
58
-
59
- # Offense count: 2
60
- # Cop supports --auto-correct.
61
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
62
- # SupportedStyles: space, no_space
63
- # SupportedStylesForEmptyBraces: space, no_space
64
- Layout/SpaceBeforeBlockBraces:
65
- Exclude:
66
- - 'spec/jwk/ec_spec.rb'
67
- - 'spec/jwt/verify_spec.rb'
68
-
69
- # Offense count: 1
70
- # Cop supports --auto-correct.
71
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
72
- # SupportedStyles: space, no_space
73
- # SupportedStylesForEmptyBraces: space, no_space
74
- Layout/SpaceInsideBlockBraces:
75
- Exclude:
76
- - 'spec/jwt/verify_spec.rb'
77
-
78
- # Offense count: 1
79
- # Cop supports --auto-correct.
80
- # Configuration parameters: EnforcedStyle.
81
- # SupportedStyles: final_newline, final_blank_line
82
- Layout/TrailingBlankLines:
83
- Exclude:
84
- - 'bin/console.rb'
85
-
86
- # Offense count: 3
87
- # Cop supports --auto-correct.
88
- # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
89
- Lint/UnusedBlockArgument:
90
- Exclude:
91
- - 'spec/jwk/decode_with_jwk_spec.rb'
92
- - 'spec/jwk/ec_spec.rb'
93
- - 'spec/jwt/verify_spec.rb'
94
-
95
- # Offense count: 2
96
- Metrics/CyclomaticComplexity:
97
- Max: 7
98
-
99
- # Offense count: 1
100
- Metrics/PerceivedComplexity:
101
- Max: 8
102
-
103
- # Offense count: 1
104
- # Cop supports --auto-correct.
105
- # Configuration parameters: MaxKeyValuePairs.
106
- Performance/RedundantMerge:
107
- Exclude:
108
- - 'spec/jwt_spec.rb'
109
-
110
- # Offense count: 1
111
- # Cop supports --auto-correct.
112
- Style/Encoding:
113
- Exclude:
114
- - 'lib/jwt/version.rb'
115
-
116
- # Offense count: 1
117
- # Cop supports --auto-correct.
118
- # Configuration parameters: InverseMethods, InverseBlocks.
119
- Style/InverseMethods:
120
- Exclude:
121
- - 'spec/jwk/ec_spec.rb'
122
-
123
- # Offense count: 2
124
- # Cop supports --auto-correct.
125
- Style/MethodCallWithoutArgsParentheses:
126
- Exclude:
127
- - 'spec/jwt_spec.rb'
128
-
129
- # Offense count: 2
130
- # Configuration parameters: EnforcedStyle.
131
- # SupportedStyles: module_function, extend_self
132
- Style/ModuleFunction:
133
- Exclude:
134
- - 'lib/jwt/algos.rb'
135
- - 'lib/jwt/signature.rb'
136
-
137
- # Offense count: 1
138
- # Cop supports --auto-correct.
139
- Style/MutableConstant:
140
- Exclude:
141
- - 'lib/jwt/version.rb'
142
-
143
- # Offense count: 1
144
- # Cop supports --auto-correct.
145
- # Configuration parameters: Strict.
146
- Style/NumericLiterals:
147
- MinDigits: 6
148
-
149
- # Offense count: 1
150
- # Cop supports --auto-correct.
151
- Style/ParallelAssignment:
152
- Exclude:
153
- - 'spec/integration/readme_examples_spec.rb'
154
-
155
- # Offense count: 11
156
- # Cop supports --auto-correct.
157
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
158
- # SupportedStyles: single_quotes, double_quotes
159
- Style/StringLiterals:
160
- Exclude:
161
- - 'bin/console.rb'
162
- - 'spec/jwk/ec_spec.rb'
163
- - 'spec/jwk/rsa_spec.rb'
164
- - 'spec/jwk_spec.rb'
165
- - 'spec/jwt_spec.rb'
166
-
167
- # Offense count: 1
168
- # Cop supports --auto-correct.
169
- # Configuration parameters: EnforcedStyleForMultiline.
170
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
171
- Style/TrailingCommaInArguments:
172
- Exclude:
173
- - 'spec/jwt_spec.rb'
174
-
175
- # Offense count: 1
176
- # Cop supports --auto-correct.
177
- Style/UnlessElse:
178
- Exclude:
179
- - 'spec/jwt_spec.rb'
180
-
181
- # Offense count: 162
182
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
183
- # URISchemes: http, https
184
- Metrics/LineLength:
185
- Max: 420
data/.sourcelevel.yml DELETED
@@ -1,18 +0,0 @@
1
- styleguide: excpt/linters
2
- engines:
3
- reek:
4
- enabled: true
5
- fixme:
6
- enabled: true
7
- rubocop:
8
- enabled: true
9
- channel: rubocop-0-52
10
- duplication:
11
- config:
12
- languages:
13
- - ruby
14
- enabled: true
15
- remark-lint:
16
- enabled: true
17
- exclude_paths:
18
- - spec
data/Appraisals DELETED
@@ -1,10 +0,0 @@
1
- appraise 'standalone' do
2
- end
3
-
4
- appraise 'openssl' do
5
- gem 'openssl', '~> 2.1'
6
- end
7
-
8
- appraise 'rbnacl' do
9
- gem 'rbnacl'
10
- end
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rubocop', '~> 0.52.0' # Same as codeclimate default
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- require 'bundler/setup'
2
- require 'bundler/gem_tasks'
3
-
4
- begin
5
- require 'rspec/core/rake_task'
6
- require 'rubocop/rake_task'
7
-
8
- RSpec::Core::RakeTask.new(:test)
9
- RuboCop::RakeTask.new(:rubocop)
10
-
11
- task default: %i[rubocop test]
12
- rescue LoadError
13
- puts 'RSpec rake tasks not available. Please run "bundle install" to install missing dependencies.'
14
- end
@@ -1,16 +0,0 @@
1
- module JWT
2
- module DefaultOptions
3
- DEFAULT_OPTIONS = {
4
- verify_expiration: true,
5
- verify_not_before: true,
6
- verify_iss: false,
7
- verify_iat: false,
8
- verify_jti: false,
9
- verify_aud: false,
10
- verify_sub: false,
11
- leeway: 0,
12
- algorithms: ['HS256'],
13
- required_claims: []
14
- }.freeze
15
- end
16
- end
@@ -1,57 +0,0 @@
1
- module JWT
2
- # Collection of security methods
3
- #
4
- # @see: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/security_utils.rb
5
- module SecurityUtils
6
- module_function
7
-
8
- def secure_compare(left, right)
9
- left_bytesize = left.bytesize
10
-
11
- return false unless left_bytesize == right.bytesize
12
-
13
- unpacked_left = left.unpack "C#{left_bytesize}"
14
- result = 0
15
- right.each_byte { |byte| result |= byte ^ unpacked_left.shift }
16
- result.zero?
17
- end
18
-
19
- def verify_rsa(algorithm, public_key, signing_input, signature)
20
- public_key.verify(OpenSSL::Digest.new(algorithm.sub('RS', 'sha')), signature, signing_input)
21
- end
22
-
23
- def verify_ps(algorithm, public_key, signing_input, signature)
24
- formatted_algorithm = algorithm.sub('PS', 'sha')
25
-
26
- public_key.verify_pss(formatted_algorithm, signature, signing_input, salt_length: :auto, mgf1_hash: formatted_algorithm)
27
- end
28
-
29
- def asn1_to_raw(signature, public_key)
30
- byte_size = (public_key.group.degree + 7) / 8
31
- OpenSSL::ASN1.decode(signature).value.map { |value| value.value.to_s(2).rjust(byte_size, "\x00") }.join
32
- end
33
-
34
- def raw_to_asn1(signature, private_key)
35
- byte_size = (private_key.group.degree + 7) / 8
36
- sig_bytes = signature[0..(byte_size - 1)]
37
- sig_char = signature[byte_size..-1] || ''
38
- OpenSSL::ASN1::Sequence.new([sig_bytes, sig_char].map { |int| OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(int, 2)) }).to_der
39
- end
40
-
41
- def rbnacl_fixup(algorithm, key)
42
- algorithm = algorithm.sub('HS', 'SHA').to_sym
43
-
44
- return [] unless defined?(RbNaCl) && RbNaCl::HMAC.constants(false).include?(algorithm)
45
-
46
- authenticator = RbNaCl::HMAC.const_get(algorithm)
47
-
48
- # Fall back to OpenSSL for keys larger than 32 bytes.
49
- return [] if key.bytesize > authenticator.key_bytes
50
-
51
- [
52
- authenticator,
53
- key.bytes.fill(0, key.bytesize...authenticator.key_bytes).pack('C*')
54
- ]
55
- end
56
- end
57
- end
data/lib/jwt/signature.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'jwt/security_utils'
4
- require 'openssl'
5
- require 'jwt/algos'
6
- begin
7
- require 'rbnacl'
8
- rescue LoadError
9
- raise if defined?(RbNaCl)
10
- end
11
-
12
- # JWT::Signature module
13
- module JWT
14
- # Signature logic for JWT
15
- module Signature
16
- extend self
17
- ToSign = Struct.new(:algorithm, :msg, :key)
18
- ToVerify = Struct.new(:algorithm, :public_key, :signing_input, :signature)
19
-
20
- def sign(algorithm, msg, key)
21
- algo, code = Algos.find(algorithm)
22
- algo.sign ToSign.new(code, msg, key)
23
- end
24
-
25
- def verify(algorithm, key, signing_input, signature)
26
- return true if algorithm.casecmp('none').zero?
27
-
28
- raise JWT::DecodeError, 'No verification key available' unless key
29
-
30
- algo, code = Algos.find(algorithm)
31
- verified = algo.verify(ToVerify.new(code, key, signing_input, signature))
32
- raise(JWT::VerificationError, 'Signature verification raised') unless verified
33
- rescue OpenSSL::PKey::PKeyError
34
- raise JWT::VerificationError, 'Signature verification raised'
35
- ensure
36
- OpenSSL.errors.clear
37
- end
38
- end
39
- end