Skip to content

Commit

Permalink
refactor(tools): remove reference of sha256 from utils (#12095)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Dec 11, 2023
1 parent 81ad18d commit ac5b634
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
7 changes: 4 additions & 3 deletions kong/db/schema/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ local _M = {}
local lrucache = require "resty.lrucache"
local jsonschema = require "resty.ljsonschema"
local metaschema = require "resty.ljsonschema.metaschema"
local utils = require "kong.tools.utils"
local cjson = require "cjson"

local sha256_hex = require("kong.tools.sha256").sha256_hex
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy

local type = type
local cjson_encode = cjson.encode
local sha256_hex = utils.sha256_hex


---@class kong.db.schema.json.schema_doc : table
Expand Down Expand Up @@ -156,7 +157,7 @@ end
---@param name string
---@param schema kong.db.schema.json.schema_doc
function _M.add_schema(name, schema)
schemas[name] = utils.cycle_aware_deep_copy(schema, true)
schemas[name] = cycle_aware_deep_copy(schema, true)
end


Expand Down
13 changes: 6 additions & 7 deletions kong/plugins/hmac-auth/access.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local constants = require "kong.constants"
local sha256 = require "resty.sha256"
local openssl_hmac = require "resty.openssl.hmac"
local utils = require "kong.tools.utils"


local sha256_base64 = require("kong.tools.sha256").sha256_base64
local string_split = require("kong.tools.string").split


local ngx = ngx
Expand All @@ -10,7 +12,6 @@ local error = error
local time = ngx.time
local abs = math.abs
local decode_base64 = ngx.decode_base64
local encode_base64 = ngx.encode_base64
local parse_time = ngx.parse_http_time
local re_gmatch = ngx.re.gmatch
local hmac_sha1 = ngx.hmac_sha1
Expand Down Expand Up @@ -115,7 +116,7 @@ local function retrieve_hmac_fields(authorization_header)
if m and #m >= 4 then
hmac_params.username = m[1]
hmac_params.algorithm = m[2]
hmac_params.hmac_headers = utils.split(m[3], " ")
hmac_params.hmac_headers = string_split(m[3], " ")
hmac_params.signature = m[4]
end
end
Expand Down Expand Up @@ -231,9 +232,7 @@ local function validate_body()
return body == ""
end

local digest = sha256:new()
digest:update(body or '')
local digest_created = "SHA-256=" .. encode_base64(digest:final())
local digest_created = "SHA-256=" .. sha256_base64(body or '')

return digest_created == digest_received
end
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/ldap-auth/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local upper = string.upper
local sub = string.sub
local fmt = string.format
local tcp = ngx.socket.tcp
local sha256_hex = require "kong.tools.utils".sha256_hex
local sha256_hex = require("kong.tools.sha256").sha256_hex


local AUTHORIZATION = "authorization"
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/proxy-cache/cache_key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local sort = table.sort
local insert = table.insert
local concat = table.concat

local sha256_hex = require "kong.tools.utils".sha256_hex
local sha256_hex = require("kong.tools.sha256").sha256_hex

local _M = {}

Expand Down
2 changes: 1 addition & 1 deletion kong/runloop/wasm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ local hash_chain
do
local buffer = require "string.buffer"

local sha256 = utils.sha256_bin
local sha256 = require("kong.tools.sha256").sha256_bin

local HASH_DISABLED = sha256("disabled")
local HASH_NONE = sha256("none")
Expand Down
1 change: 0 additions & 1 deletion kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local _M = {}
do
local modules = {
"kong.tools.table",
"kong.tools.sha256",
"kong.tools.yield",
"kong.tools.string",
"kong.tools.uuid",
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/20-ldap-auth/01-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local cjson = require "cjson"

local lower = string.lower
local fmt = string.format
local sha256_hex = require "kong.tools.utils".sha256_hex
local sha256_hex = require("kong.tools.sha256").sha256_hex


local function cache_key(conf, username, password)
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/20-ldap-auth/02-invalidations_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local helpers = require "spec.helpers"
local fmt = string.format
local lower = string.lower
local sha256_hex = require "kong.tools.utils".sha256_hex
local sha256_hex = require("kong.tools.sha256").sha256_hex

local ldap_host_aws = "ec2-54-172-82-117.compute-1.amazonaws.com"

Expand Down

0 comments on commit ac5b634

Please sign in to comment.