Module: Paseto
- Defined in:
- lib/paseto.rb,
lib/paseto/error.rb,
lib/paseto/local.rb,
lib/paseto/token.rb,
lib/paseto/public.rb,
lib/paseto/version.rb
Defined Under Namespace
Modules: V2
Classes: Token
Constant Summary
collapse
''.freeze
- UNSIGNED_LITTLE_64 =
An Array#pack format to pack an unsigned little-endian 64-bit integer
'Q<'.freeze
- Error =
Class.new(StandardError)
Class.new(Error)
- TokenError =
Class.new(Error)
- AuthenticationError =
Class.new(Error)
- VERSION =
"0.3.1"
Class Method Summary
collapse
Class Method Details
.decode64(str) ⇒ Object
31
32
33
|
# File 'lib/paseto.rb', line 31
def self.decode64(str)
Base64.urlsafe_decode64(str)
end
|
.encode64(bin) ⇒ Object
35
36
37
38
|
# File 'lib/paseto.rb', line 35
def self.encode64(bin)
Base64.urlsafe_encode64(bin).gsub(/=+$/, '')
end
|
.encode_length(n) ⇒ Object
17
18
19
|
# File 'lib/paseto.rb', line 17
def self.encode_length(n)
[n].pack(UNSIGNED_LITTLE_64)
end
|
.parse(raw) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/paseto/token.rb', line 28
def self.parse(raw)
version, purpose, payload, = raw.split('.')
= "#{version}.#{purpose}"
= .nil? ? EMPTY_FOOTER : Paseto.decode64()
payload = Paseto.decode64(payload) unless payload.nil?
Token.new(, payload, )
end
|
.pre_auth_encode(*pieces) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/paseto.rb', line 22
def self.pre_auth_encode(*pieces)
initial_output = encode_length(pieces.length)
pieces.reduce(initial_output) do |output, piece|
output += encode_length(piece.length)
output += piece
end
end
|
.verify_token(token, expected_header, expected_footer) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/paseto/token.rb', line 15
def self.verify_token(token, , )
token = parse(token) unless token.is_a? Token
if token. !=
raise HeaderError.new("Invalid message header: #{token.}")
end
if token. !=
raise TokenError.new("Invalid message footer: #{token..inspect}")
end
token
end
|