2021-08-09 17:43:42 +02:00
|
|
|
local b64 = require("ngx.base64") -- only contains URL-variants
|
|
|
|
|
|
|
|
if not b64["decode_base64"] then
|
|
|
|
b64.decode_base64 = function(base64)
|
|
|
|
base64 = base64:gsub("%+", "-")
|
|
|
|
base64 = base64:gsub("/", "_")
|
|
|
|
return b64.decode_base64url(base64)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not b64["encode_base64"] then
|
|
|
|
b64.encode_base64 = function(plaintext)
|
2021-09-02 22:58:01 +02:00
|
|
|
local plain, err = b64.encode_base64url(plaintext)
|
|
|
|
if not plain then
|
|
|
|
return nil, err
|
|
|
|
end
|
2021-08-09 17:43:42 +02:00
|
|
|
plain = plain:gsub("_", "/")
|
2021-09-02 22:58:01 +02:00
|
|
|
return plain:gsub("%-", "+"), nil
|
2021-08-09 17:43:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return b64
|