branca-ruby 1.0.2 → 1.0.4

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: b6008ca4fddab057ac61a6182d54fe929ffef0f1007cd85cb2ca783f848487e7
4
- data.tar.gz: 2d9e5726a85bf9f3c942420c1e0c03abbff3c703c2a931db2a0b617ef2199efe
3
+ metadata.gz: a18a64bfdd3003e06e8cf821c88851354edab732357676b3b86014a62fd6a172
4
+ data.tar.gz: 281778e2b9e47f9ba6d92a982c5b7e3adfae2cab7a0eee7e2e1610ea143677eb
5
5
  SHA512:
6
- metadata.gz: 7dc856d37376efd217e5ef37acb3ddada82f6fcf0a0140ed59b6b57dc77094fd43c40d85ee6ce5bddd8766944e91278eb15deb92624424d3e91b38dffa2693ed
7
- data.tar.gz: 356d90d5e2203ad66b86260d28e7808874e43386e69fc87315dd9d23c4c92be53d9c7158f0c9ca7d46dcb848031b0fefaa40e729174c8cf1fe79345559342cb2
6
+ metadata.gz: 8b80e5b4e5df1e1ffa41ac6cf95c2dd861c9db446cfbed290d84cdafebeea41370ccd819add02d4a5949a3de25c72c5e46179ac700ffefa866f50e8b7b8162eb
7
+ data.tar.gz: a37487ab60fe01d67e1ee7d49c4e57e64bb0afda1554a4e5708fcde5c09d450d15497022a9e0190dbab4e200e75037a7c193cd9e192c550e626f7f7a0ae73055
@@ -0,0 +1,13 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [thadeu] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/.gitpod.yml ADDED
@@ -0,0 +1,8 @@
1
+ # This configuration file was automatically generated by Gitpod.
2
+ # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
3
+ # and commit this file to your remote git repository to share the goodness with others.
4
+
5
+ tasks:
6
+ - init: bin/setup
7
+
8
+
data/Gemfile CHANGED
@@ -7,4 +7,4 @@ gemspec
7
7
 
8
8
  ruby '>= 2.5.8'
9
9
 
10
- gem "byebug", "~> 10.0", :group => :test
10
+ gem "byebug", :group => :test
data/README.md CHANGED
@@ -17,7 +17,7 @@ It is possible to use [Branca as an alternative to JWT](https://appelsiini.net/2
17
17
  Add this line to your application's Gemfile, Note that you also must have [libsodium](https://download.libsodium.org/doc/) installed.
18
18
 
19
19
  ```ruby
20
- gem 'branca-ruby', '~> 1.0.2'
20
+ gem 'branca-ruby', '~> 1.0.3'
21
21
  ```
22
22
 
23
23
  ## Configure
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Branca
4
- class VersionError < StandardError; end
4
+ class Error < StandardError; end
5
+
6
+ class VersionError < Error; end
5
7
 
6
- class DecodeError < StandardError
8
+ class DecodeError < Error
7
9
  def to_s
8
10
  "Can't decode token"
9
11
  end
10
12
  end
11
13
 
12
- class ExpiredTokenError < StandardError
14
+ class ExpiredTokenError < Error
13
15
  def to_s
14
16
  'Token is expired'
15
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Branca
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
data/lib/branca.rb CHANGED
@@ -21,7 +21,7 @@ module Branca
21
21
  ciphertext = cipher.encrypt(nonce, message, header)
22
22
  raw_token = header + ciphertext
23
23
 
24
- BaseX::Base62.encode(raw_token)
24
+ base62_encode(raw_token)
25
25
  end
26
26
 
27
27
  def decode(token, ttl: self.ttl, secret_key: self.secret_key)
@@ -58,12 +58,28 @@ module Branca
58
58
  end
59
59
 
60
60
  def token_explode(token)
61
- bytes = BaseX::Base62.decode(token).unpack('C C4 C24 C*')
61
+ raw = base62_decode(token)
62
+ bytes = raw.unpack('C C4 C24 C*')
62
63
  header = bytes.shift(1 + 4 + 24)
63
64
 
64
65
  [header, bytes]
65
66
  end
66
67
 
68
+ BASE62_NO_LEADING_ZERO = BaseX.new(
69
+ '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0'
70
+ ).freeze
71
+
72
+ def base62_encode(raw_token)
73
+ BASE62_NO_LEADING_ZERO.encode(raw_token)
74
+ end
75
+
76
+ def base62_decode(token)
77
+ raw = BASE62_NO_LEADING_ZERO.decode(token)
78
+ return raw if raw.getbyte(0) == VERSION
79
+
80
+ BaseX::Base62.decode(token)
81
+ end
82
+
67
83
  def header_explode(header)
68
84
  version = header[0]
69
85
  nonce = header[5..header.size].pack('C*')
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branca-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-05-26 00:00:00.000000000 Z
10
+ date: 2026-02-10 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: base_x
@@ -101,8 +100,10 @@ executables: []
101
100
  extensions: []
102
101
  extra_rdoc_files: []
103
102
  files:
103
+ - ".github/FUNDING.yml"
104
104
  - ".github/workflows/ruby.yml"
105
105
  - ".gitignore"
106
+ - ".gitpod.yml"
106
107
  - ".rspec"
107
108
  - ".rubocop.yml"
108
109
  - ".travis-libsodium.sh"
@@ -122,7 +123,6 @@ homepage: https://github.com/thadeu/branca-ruby
122
123
  licenses:
123
124
  - MIT
124
125
  metadata: {}
125
- post_install_message:
126
126
  rdoc_options: []
127
127
  require_paths:
128
128
  - lib
@@ -137,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.1.2
141
- signing_key:
140
+ rubygems_version: 3.6.2
142
141
  specification_version: 4
143
142
  summary: Authenticated and encrypted API tokens using modern crypto
144
143
  test_files: []