Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(plugins/jwt): use string.buffer to replace table.concat #12075

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions kong/plugins/jwt/jwt_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

local json = require "cjson"
local b64 = require "ngx.base64"
local buffer = require "string.buffer"
local openssl_digest = require "resty.openssl.digest"
local openssl_hmac = require "resty.openssl.hmac"
local openssl_pkey = require "resty.openssl.pkey"
Expand All @@ -20,7 +21,6 @@ local time = ngx.time
local pairs = pairs
local error = error
local pcall = pcall
local concat = table.concat
local insert = table.insert
local unpack = unpack
local assert = assert
Expand Down Expand Up @@ -237,17 +237,17 @@ local function encode_token(data, key, alg, header)
end

local header = header or { typ = "JWT", alg = alg }
local segments = {
base64_encode(json.encode(header)),
base64_encode(json.encode(data))
}
local buf = buffer.new()

buf:put(base64_encode(json.encode(header))):put(".")
:put(base64_encode(json.encode(data)))

local signing_input = concat(segments, ".")
local signature = alg_sign[alg](signing_input, key)
local signature = alg_sign[alg](buf:tostring(), key)

segments[#segments+1] = base64_encode(signature)
buf:put(".")
:put(base64_encode(signature))

return concat(segments, ".")
return buf:get()
end


Expand Down
Loading