@@ -21,17 +21,13 @@ data.verify = {
2121 end ,
2222}
2323
24- local function urlSafe (base64 )
25- return base64 :gsub (' +' ,' -' ):gsub (' /' ,' _' ):gsub (' =' ,' ' )
26- end
27-
2824function 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 )
3531end
3632
3733function 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
0 commit comments