Skip to content

Commit 27db708

Browse files
committed
Upgrade basexx, remove url64 hacks
1 parent 7ba828a commit 27db708

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

jwt-0.3-2.rockspec renamed to jwt-0.4-0.rockspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package = "jwt"
2-
version = "0.3-2"
2+
version = "0.4-0"
33
source = {
4-
url = "https://github.com/Olivine-Labs/lua-jwt/archive/v0.3.tar.gz",
5-
dir = "lua-jwt-0.3"
4+
url = "https://github.com/Olivine-Labs/lua-jwt/archive/v0.4.tar.gz",
5+
dir = "lua-jwt-0.4"
66
}
77
description = {
88
summary = "A library for encoding and decoding json web tokens.",
@@ -15,7 +15,7 @@ dependencies = {
1515
"lua >= 5.1",
1616
"busted >= 1.7-1",
1717
"luacrypto >= 0.3.2-1",
18-
"basexx >= 0.1.0-1"
18+
"basexx >= 0.2.0-0"
1919
}
2020
build = {
2121
type = "builtin",

src/jwt.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ function data.decode(str, options)
5252
if not str then return nil, "Parameter 1 cannot be nil" end
5353
local dotFirst = str:find("%.")
5454
if not dotFirst then return nil, "Invalid token" end
55-
str = str:gsub('-','+'):gsub('_','/')
56-
local header = json.decode((basexx.from_base64(str:sub(1,dotFirst-1))))
55+
local header = json.decode((basexx.from_url64(str:sub(1,dotFirst-1))))
5756

5857
return getJwt(header):decode(header, str, options)
5958
end

src/jwt/jws.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ data.verify = {
2121
end,
2222
}
2323

24-
local function urlSafe(base64)
25-
return base64:gsub('+','-'):gsub('/','_'):gsub('=','')
26-
end
27-
2824
function data:encode(header, claims, options)
2925
if not options then error("options are required") end
3026
if not options.keys then error("keys are required") end
31-
local envelope = urlSafe(basexx.to_base64(json.encode(header)).."."..basexx.to_base64(json.encode(claims)))
27+
local envelope = basexx.to_url64(json.encode(header)).."."..basexx.to_url64(json.encode(claims))
3228
local signature, err = self.sign[header.alg](envelope, options.keys.private)
3329
if not signature then error('failed to generate signature') end
34-
return envelope ..'.'..urlSafe(basexx.to_base64(signature))
30+
return envelope ..'.'..basexx.to_url64(signature)
3531
end
3632

3733
function data:decode(header, str, options)
@@ -44,7 +40,7 @@ function data:decode(header, str, options)
4440
if dotSecond then
4541
bodyStr = str:sub(1, dotSecond-1)
4642
if options and options.keys and options.keys.public then
47-
signature = basexx.from_base64(str:sub(dotSecond+1))
43+
signature = basexx.from_url64(str:sub(dotSecond+1))
4844
end
4945
else
5046
if options and options.keys and options.keys.public then
@@ -53,9 +49,9 @@ function data:decode(header, str, options)
5349
bodyStr = str
5450
end
5551

56-
local message = basexx.from_base64(bodyStr)
52+
local message = basexx.from_url64(bodyStr)
5753
if signature then
58-
if not self.verify[header.alg](urlSafe(rawHeader).."."..urlSafe(bodyStr), signature, options.keys.public) then
54+
if not self.verify[header.alg](rawHeader.."."..bodyStr, signature, options.keys.public) then
5955
return nil, "Invalid token"
6056
end
6157
end

src/jwt/plain.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local json = require 'cjson'
44
local data = {}
55

66
function data:encode(header, claims)
7-
return basexx.to_base64(json.encode(claims))
7+
return basexx.to_url64(json.encode(claims))
88
end
99

1010
function data:decode(header, str, options)
@@ -13,7 +13,7 @@ function data:decode(header, str, options)
1313
str = str:sub(dotFirst+1)
1414
local dotSecond = str:find("%.")
1515
if dotSecond then return nil, 'Invalid Token, alg=none but has signature' end
16-
return json.decode(basexx.from_base64(str))
16+
return json.decode(basexx.from_url64(str))
1717
end
1818

1919
return data

0 commit comments

Comments
 (0)