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 +4 -4
- data/.github/FUNDING.yml +13 -0
- data/.gitpod.yml +8 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/branca/exceptions.rb +5 -3
- data/lib/branca/version.rb +1 -1
- data/lib/branca.rb +18 -2
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a18a64bfdd3003e06e8cf821c88851354edab732357676b3b86014a62fd6a172
|
|
4
|
+
data.tar.gz: 281778e2b9e47f9ba6d92a982c5b7e3adfae2cab7a0eee7e2e1610ea143677eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b80e5b4e5df1e1ffa41ac6cf95c2dd861c9db446cfbed290d84cdafebeea41370ccd819add02d4a5949a3de25c72c5e46179ac700ffefa866f50e8b7b8162eb
|
|
7
|
+
data.tar.gz: a37487ab60fe01d67e1ee7d49c4e57e64bb0afda1554a4e5708fcde5c09d450d15497022a9e0190dbab4e200e75037a7c193cd9e192c550e626f7f7a0ae73055
|
data/.github/FUNDING.yml
ADDED
|
@@ -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
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.
|
|
20
|
+
gem 'branca-ruby', '~> 1.0.3'
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Configure
|
data/lib/branca/exceptions.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Branca
|
|
4
|
-
class
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class VersionError < Error; end
|
|
5
7
|
|
|
6
|
-
class DecodeError <
|
|
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 <
|
|
14
|
+
class ExpiredTokenError < Error
|
|
13
15
|
def to_s
|
|
14
16
|
'Token is expired'
|
|
15
17
|
end
|
data/lib/branca/version.rb
CHANGED
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
|
-
|
|
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
|
-
|
|
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.
|
|
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:
|
|
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.
|
|
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: []
|