hmac 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0da92960c7fa56af039d5ff4422bf8639e3cabafd4a948bfafb5106c61f6370a
4
+ data.tar.gz: 9d060d4d8289a347d5ec042596c522080456fb48869a5827efb4cb6be9609820
5
+ SHA512:
6
+ metadata.gz: 24ebf43647946a309f3538f4d1f379acc9687922de50500c77199e1faac1d07b7f6c81d7cba6e9eecf3de3880bdd06573cdb9b437f6e3bff6a0b45d8e69a2daa
7
+ data.tar.gz: d595bc49f1742dfaae7f8f3e2dc1ae931caf3cac3946503ccc08c2a8b9473aa91739bfd9d4718b3a25e9927866eb65636676828cbd68f6e70936d6f074ab6927
@@ -0,0 +1,13 @@
1
+ version: 2.1
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: ruby:3.1
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Run the default task
10
+ command: |
11
+ gem install bundler -v 2.3.10
12
+ bundle install
13
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,226 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+ Exclude:
4
+ - bin/**/*
5
+ <% `git status --ignored --porcelain`.scan(/^!!\s+(.*)$/).each do |match| %>
6
+ - <%= match[0] %>**/*
7
+ <% end %>
8
+
9
+ # Extensions
10
+ require:
11
+ - rubocop-rake
12
+ - rubocop-rspec
13
+
14
+ # New rules
15
+ Lint/DuplicateBranch: # (new in 1.3)
16
+ Enabled: true
17
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
18
+ Enabled: true
19
+ Lint/EmptyBlock: # (new in 1.1)
20
+ Enabled: true
21
+ Lint/EmptyClass: # (new in 1.3)
22
+ Enabled: true
23
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
24
+ Enabled: true
25
+ Lint/ToEnumArguments: # (new in 1.1)
26
+ Enabled: true
27
+ Lint/UnexpectedBlockArity: # (new in 1.5)
28
+ Enabled: true
29
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
30
+ Enabled: true
31
+ Style/ArgumentsForwarding: # (new in 1.1)
32
+ Enabled: true
33
+ Style/CollectionCompact: # (new in 1.2)
34
+ Enabled: true
35
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
36
+ Enabled: true
37
+ Style/NegatedIfElseCondition: # (new in 1.2)
38
+ Enabled: true
39
+ Style/NilLambda: # (new in 1.3)
40
+ Enabled: true
41
+ Style/RedundantArgument: # (new in 1.4)
42
+ Enabled: true
43
+ Style/SwapValues: # (new in 1.1)
44
+ Enabled: true
45
+ Gemspec/DateAssignment: # (new in 1.10)
46
+ Enabled: true
47
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
48
+ Enabled: true
49
+ Lint/AmbiguousAssignment: # (new in 1.7)
50
+ Enabled: true
51
+ Lint/DeprecatedConstants: # (new in 1.8)
52
+ Enabled: true
53
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
54
+ Enabled: true
55
+ Lint/NumberedParameterAssignment: # (new in 1.9)
56
+ Enabled: true
57
+ Lint/OrAssignmentToConstant: # (new in 1.9)
58
+ Enabled: true
59
+ Lint/RedundantDirGlobSort: # (new in 1.8)
60
+ Enabled: true
61
+ Lint/SymbolConversion: # (new in 1.9)
62
+ Enabled: true
63
+ Lint/TripleQuotes: # (new in 1.9)
64
+ Enabled: true
65
+ Style/EndlessMethod: # (new in 1.8)
66
+ Enabled: true
67
+ Style/HashConversion: # (new in 1.10)
68
+ Enabled: true
69
+ Style/HashExcept: # (new in 1.7)
70
+ Enabled: true
71
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
72
+ Enabled: true
73
+ Gemspec/RequireMFA: # new in 1.23
74
+ Enabled: true
75
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
76
+ Enabled: true
77
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
78
+ Enabled: true
79
+ Lint/AmbiguousRange: # new in 1.19
80
+ Enabled: true
81
+ Lint/EmptyInPattern: # new in 1.16
82
+ Enabled: true
83
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
84
+ Enabled: true
85
+ Lint/RequireRelativeSelfPath: # new in 1.22
86
+ Enabled: true
87
+ Lint/UselessRuby2Keywords: # new in 1.23
88
+ Enabled: true
89
+ Naming/BlockForwarding: # new in 1.24
90
+ Enabled: true
91
+ Security/IoMethods: # new in 1.22
92
+ Enabled: true
93
+ Style/FileRead: # new in 1.24
94
+ Enabled: true
95
+ Style/FileWrite: # new in 1.24
96
+ Enabled: true
97
+ Style/InPatternThen: # new in 1.16
98
+ Enabled: true
99
+ Style/MapToHash: # new in 1.24
100
+ Enabled: true
101
+ Style/MultilineInPatternThen: # new in 1.16
102
+ Enabled: true
103
+ Style/NumberedParameters: # new in 1.22
104
+ Enabled: true
105
+ Style/NumberedParametersLimit: # new in 1.22
106
+ Enabled: true
107
+ Style/OpenStructUse: # new in 1.23
108
+ Enabled: true
109
+ Style/QuotedSymbols: # new in 1.16
110
+ Enabled: true
111
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
112
+ Enabled: true
113
+ Style/SelectByRegexp: # new in 1.22
114
+ Enabled: true
115
+ Style/StringChars: # new in 1.12
116
+ Enabled: true
117
+ RSpec/ExcessiveDocstringSpacing: # new in 2.5
118
+ Enabled: true
119
+ RSpec/IdenticalEqualityAssertion: # new in 2.4
120
+ Enabled: true
121
+ RSpec/SubjectDeclaration: # new in 2.5
122
+ Enabled: true
123
+ RSpec/FactoryBot/SyntaxMethods: # new in 2.7
124
+ Enabled: true
125
+ RSpec/Rails/AvoidSetupHook: # new in 2.4
126
+ Enabled: true
127
+ Style/NestedFileDirname: # new in 1.26
128
+ Enabled: true
129
+ RSpec/BeEq: # new in 2.9.0
130
+ Enabled: true
131
+ RSpec/BeNil: # new in 2.9.0
132
+ Enabled: true
133
+ Lint/RefinementImportMethods: # new in 1.27
134
+ Enabled: true
135
+ Style/RedundantInitialize: # new in 1.27
136
+ Enabled: true
137
+
138
+ # Alterations
139
+ Naming/RescuedExceptionsVariableName:
140
+ Enabled: false
141
+ Style/BlockComments:
142
+ Exclude:
143
+ - spec/**/*
144
+ Style/Documentation:
145
+ Enabled: false
146
+ Style/FrozenStringLiteralComment:
147
+ Enabled: false
148
+ Layout/MultilineMethodCallIndentation:
149
+ Enabled: false
150
+ Style/StringLiterals:
151
+ EnforcedStyle: double_quotes
152
+ Layout/AccessModifierIndentation:
153
+ EnforcedStyle: outdent
154
+ RSpec/NestedGroups:
155
+ Enabled: false
156
+ RSpec/MultipleMemoizedHelpers:
157
+ Enabled: false
158
+ RSpec/MultipleExpectations:
159
+ Enabled: false
160
+ RSpec/ExampleLength:
161
+ Enabled: false
162
+ RSpec/ContextWording:
163
+ Prefixes:
164
+ - but
165
+ - if
166
+ - when
167
+ - with
168
+ - without
169
+ RSpec/AnyInstance:
170
+ Enabled: false
171
+ Metrics/BlockLength:
172
+ Exclude:
173
+ - spec/**/*
174
+ Layout/ArgumentAlignment:
175
+ Enabled: false
176
+ Style/TrailingCommaInArrayLiteral:
177
+ EnforcedStyleForMultiline: consistent_comma
178
+ Style/TrailingCommaInArguments:
179
+ EnforcedStyleForMultiline: consistent_comma
180
+ Style/TrailingCommaInHashLiteral:
181
+ EnforcedStyleForMultiline: consistent_comma
182
+ Layout/MultilineMethodCallBraceLayout:
183
+ EnforcedStyle: new_line
184
+ Style/AsciiComments:
185
+ Enabled: false
186
+ Layout/CaseIndentation:
187
+ EnforcedStyle: end
188
+ Style/Lambda:
189
+ Enabled: false
190
+ Layout/SpaceInLambdaLiteral:
191
+ Enabled: false
192
+ Style/RedundantSelf:
193
+ Enabled: false
194
+ Style/PreferredHashMethods:
195
+ EnforcedStyle: verbose
196
+ Style/IfUnlessModifier:
197
+ Enabled: false
198
+ Layout/EndAlignment:
199
+ EnforcedStyleAlignWith: variable
200
+ Style/BlockDelimiters:
201
+ EnforcedStyle: semantic
202
+ AllowBracesOnProceduralOneLiners: true
203
+ Style/GuardClause:
204
+ Enabled: false
205
+ Metrics/MethodLength:
206
+ Enabled: false
207
+ Naming/MethodParameterName:
208
+ AllowedNames:
209
+ - as
210
+ - id
211
+ Metrics/AbcSize:
212
+ Enabled: false
213
+ Style/IfUnlessModifierOfIfUnless:
214
+ Enabled: false
215
+ Style/NestedModifier:
216
+ Enabled: false
217
+ Style/SoleNestedConditional:
218
+ Enabled: false
219
+ Naming/VariableNumber:
220
+ EnforcedStyle: snake_case
221
+ RSpec/SubjectStub:
222
+ Enabled: false
223
+ Layout/ArrayAlignment:
224
+ Enabled: false
225
+ Layout/FirstArrayElementIndentation:
226
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2022-04-13
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in hmac.gemspec
6
+ gemspec
7
+
8
+ gem "climate_control", "~> 1.0"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.11"
11
+ gem "rubocop", "~> 1.7"
12
+ gem "rubocop-rake", "~> 0.6"
13
+ gem "rubocop-rspec", "~> 2.9"
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hmac (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ climate_control (1.0.1)
11
+ diff-lcs (1.5.0)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.3.0)
18
+ rexml (3.2.5)
19
+ rspec (3.11.0)
20
+ rspec-core (~> 3.11.0)
21
+ rspec-expectations (~> 3.11.0)
22
+ rspec-mocks (~> 3.11.0)
23
+ rspec-core (3.11.0)
24
+ rspec-support (~> 3.11.0)
25
+ rspec-expectations (3.11.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.11.0)
28
+ rspec-mocks (3.11.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.11.0)
31
+ rspec-support (3.11.0)
32
+ rubocop (1.27.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 3.1.0.0)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml
38
+ rubocop-ast (>= 1.16.0, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 3.0)
41
+ rubocop-ast (1.17.0)
42
+ parser (>= 3.1.1.0)
43
+ rubocop-rake (0.6.0)
44
+ rubocop (~> 1.0)
45
+ rubocop-rspec (2.9.0)
46
+ rubocop (~> 1.19)
47
+ ruby-progressbar (1.11.0)
48
+ unicode-display_width (2.1.0)
49
+
50
+ PLATFORMS
51
+ x86_64-darwin-19
52
+ x86_64-darwin-21
53
+
54
+ DEPENDENCIES
55
+ climate_control (~> 1.0)
56
+ hmac!
57
+ rake (~> 13.0)
58
+ rspec (~> 3.11)
59
+ rubocop (~> 1.7)
60
+ rubocop-rake (~> 0.6)
61
+ rubocop-rspec (~> 2.9)
62
+
63
+ BUNDLED WITH
64
+ 2.3.10
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Smart/Casual Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # HMAC
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'hmac'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hmac
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SmartCasual/hmac.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "rspec/core/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hmac"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/hmac.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hmac/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hmac"
7
+ spec.version = HMAC::VERSION
8
+ spec.authors = ["Elliot Crosby-McCullough"]
9
+ spec.email = ["elliot.cm@gmail.com"]
10
+
11
+ spec.summary = "A utility for generating and validating HMAC signatures"
12
+ spec.homepage = "https://github.com/SmartCasual/hmac"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/SmartCasual/hmac/blob/#{spec.version}/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) {
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ }
26
+ spec.require_paths = ["lib"]
27
+ spec.metadata["rubygems_mfa_required"] = "true"
28
+ end
@@ -0,0 +1,33 @@
1
+ module HMAC
2
+ class Generator
3
+ def initialize(context:, public: false)
4
+ @context = context
5
+ @public = public
6
+ @digest = OpenSSL::Digest.new("SHA256")
7
+ @hmac_key = ENV.fetch("HMAC_SECRET")
8
+ end
9
+
10
+ def generate(id:)
11
+ OpenSSL::HMAC
12
+ .new(hmac_key, digest)
13
+ .update(id.to_s)
14
+ .update(context)
15
+ .tap { |hmac| hmac.update("public") if public? }
16
+ .hexdigest
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader(
22
+ *%I[
23
+ context
24
+ digest
25
+ hmac_key
26
+ ],
27
+ )
28
+
29
+ def public?
30
+ !!@public
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module HMAC
2
+ class Validator
3
+ def initialize(...)
4
+ @generator = HMAC::Generator.new(...)
5
+ end
6
+
7
+ def validate(hmac, against_id:)
8
+ present?(hmac) && hmac == @generator.generate(id: against_id)
9
+ end
10
+
11
+ private
12
+
13
+ def present?(string)
14
+ !string.nil? && !string.empty?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HMAC
4
+ VERSION = "1.0.0"
5
+ end
data/lib/hmac.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HMAC; end
4
+
5
+ require_relative "hmac/generator"
6
+ require_relative "hmac/validator"
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hmac
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Elliot Crosby-McCullough
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - elliot.cm@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".circleci/config.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".ruby-version"
25
+ - CHANGELOG.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENCE
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - hmac.gemspec
34
+ - lib/hmac.rb
35
+ - lib/hmac/generator.rb
36
+ - lib/hmac/validator.rb
37
+ - lib/hmac/version.rb
38
+ homepage: https://github.com/SmartCasual/hmac
39
+ licenses: []
40
+ metadata:
41
+ allowed_push_host: https://rubygems.org
42
+ homepage_uri: https://github.com/SmartCasual/hmac
43
+ source_code_uri: https://github.com/SmartCasual/hmac
44
+ changelog_uri: https://github.com/SmartCasual/hmac/blob/1.0.0/CHANGELOG.md
45
+ rubygems_mfa_required: 'true'
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.3.7
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A utility for generating and validating HMAC signatures
65
+ test_files: []