mac 0.1.0 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bdaba057d3367392da97d8afd0cd5f1b5973686b97c3028757eb50f11d8f8c7
4
- data.tar.gz: 78fcc37df2f60f67c8eeeddf28619931b0f55f0f61b9a72bc8dcc06234962d04
3
+ metadata.gz: e8c78e4cd9f0ee48b31be15a0c68692735c6c6ef4bab6b68787c0b65052e2d10
4
+ data.tar.gz: 2d7189ac699222bc97b1a0c80cafa183e174b37fec38b1d834d5c3be3e3da445
5
5
  SHA512:
6
- metadata.gz: 64fd0408a3848dcb93734bd80b230e6a2ff25f574bcb4e8289144332eb5cde51f9077da7eea7a96c89060c039a53b7ff9d5a4583fd9074820b18e83481fd961b
7
- data.tar.gz: 0eba94242ffe369676dea2c52a2924410a5ef0d832990763bde0387de299603d539688e60551be6521d2e3290d8f56701b38a1130e62c911cb395b3474598616
6
+ metadata.gz: d221e300acfc8578f3dd2d148304a24444c8ccac090e2c605c02db46c475d35f0b94f88be56f2b67bbbd292893608d18cf322dbadb86fb2cc3d0c9bda3714329
7
+ data.tar.gz: '084d2e9304f1a405afe9cfecb2ead7bc47c8eeaf09947577c3d9d7b2775bba148a5c31c8b05b099c273f9958eb093dac8288acaea720b824b533d4383c4bb16d'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,3 @@
1
- ## [Unreleased]
1
+ ## [1.0.0] - 2026-05-24
2
2
 
3
- ## [0.1.0] - 2026-05-24
4
-
5
- - Initial release
3
+ - Initial release: Mac class with `sign` and `verify` methods.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2026 claudiob
3
+ Copyright (c) 2026 HouseAccount
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,39 +1,18 @@
1
- # Mac
1
+ # Message Authentication Code (MAC) with SHA256 and signature
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ ## Available methods
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mac`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Sign a message:
6
6
 
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
7
+ ```ruby
8
+ mac = Mac.sign message:, secret:
9
+ mac.timestamp # => 1779489515999
10
+ mac.signature # => 46f5297a94d0050ba6039bfcb12d6e4c1f955e39b34f98cf2bd5f9720b34ac49
15
11
  ```
16
12
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
13
+ Verify a signed message:
18
14
 
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```ruby
16
+ mac = Mac.new message:, secret:
17
+ mac.signed? signature:, timestamp: # true
21
18
  ```
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- 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).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mac.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/mac.rb CHANGED
@@ -1,8 +1,35 @@
1
- # frozen_string_literal: true
1
+ # Provides methods to sign and verify timestamped messages with HMAC SHA256.
2
+ class Mac
3
+ # Sets up a message to be signed/verified with a secret.
4
+ def initialize(message:, secret:, timed: true)
5
+ @message = message
6
+ @secret = secret
7
+ @timed = timed
8
+ end
2
9
 
3
- require_relative "mac/version"
10
+ # Sets up a message and calculates its current signature.
11
+ def self.sign(message:, secret:, timed: true, hexdigest: true)
12
+ new(message: message, secret: secret).tap do |mac|
13
+ mac.sign timestamp: (Time.now if timed), hexdigest: hexdigest
14
+ end
15
+ end
4
16
 
5
- module Mac
6
- class Error < StandardError; end
7
- # Your code goes here...
17
+ attr_reader :signature, :timestamp
18
+
19
+ # Returns whether the provided signature and timestamp match the signature of the message.
20
+ def signed?(signature:, timestamp: nil, hexdigest: true)
21
+ sign hexdigest: hexdigest, timestamp: timestamp
22
+ Rack::Utils.secure_compare @signature, signature
23
+ end
24
+
25
+ # Calculates the signature of the message.
26
+ def sign(timestamp: nil, hexdigest: true)
27
+ @timestamp = timestamp.to_i.to_s if timestamp
28
+ payload = [@timestamp, @message].compact.join '.'
29
+ @signature = if hexdigest
30
+ OpenSSL::HMAC.hexdigest 'SHA256', @secret, payload
31
+ else
32
+ Base64.strict_encode64(OpenSSL::HMAC.digest 'SHA256', @secret, payload)
33
+ end
34
+ end
8
35
  end
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  description: Enhances OpenSSL::HMAC with timestamp.
13
27
  email:
14
28
  - claudiob@users.noreply.github.com
@@ -19,10 +33,7 @@ files:
19
33
  - CHANGELOG.md
20
34
  - LICENSE.txt
21
35
  - README.md
22
- - Rakefile
23
36
  - lib/mac.rb
24
- - lib/mac/version.rb
25
- - sig/mac.rbs
26
37
  homepage: https://github.com/HouseAccountEng/mac
27
38
  licenses:
28
39
  - MIT
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/lib/mac/version.rb DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mac
4
- VERSION = "0.1.0"
5
- end
data/sig/mac.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Mac
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end