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

Decoder doesnt take custom spad into consideration #5

Open
onavratil-monetplus opened this issue Apr 6, 2022 · 1 comment
Open

Comments

@onavratil-monetplus
Copy link

In base64.lua in function base64.decode

  • pattern = ('[^%%w%%%s%%%s%%=]'):format( char(s62), char(s63) )
  • local padding = b64:sub(-2) == '==' and 2 or b64:sub(-1) == '=' and 1 or 0

These should be replaced with spad in both cases, with proper escapeing

@onavratil-monetplus
Copy link
Author

onavratil-monetplus commented Apr 6, 2022

function base64.decode( b64, decoder, usecaching )
	decoder = decoder or DEFAULT_DECODER
	local pattern = '[^%w%+%/%=]'
    local spad = string.byte('=')
	if decoder then
		local s62, s63
		for charcode, b64code in pairs( decoder ) do
			if b64code == 62 then s62 = charcode
			elseif b64code == 63 then s63 = charcode
			elseif b64code == 64 then spad = charcode
			end
		end
		pattern = ('[^%%w%%%s%%%s%%%s]'):format( char(s62), char(s63), char(spad) )
	end
	b64 = b64:gsub( pattern, '' )
	local cache = usecaching and {}
	local t, k = {}, 1
	local n = #b64
	local padding = b64:sub(-2) == char(spad):rep(2) and 2 or b64:sub(-1) == char(spad) and 1 or 0
	for i = 1, padding > 0 and n-4 or n, 4 do
		local a, b, c, d = b64:byte( i, i+3 )
		local s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant