2015-03-31 20:48:00 +02:00
|
|
|
base64 = {}
|
2013-01-19 01:16:01 +01:00
|
|
|
|
2015-03-31 20:48:00 +02:00
|
|
|
-- encode a string and return a base64 string
|
|
|
|
|
function base64.encode(s)
|
2015-04-06 08:25:42 +02:00
|
|
|
if package.loaded["mime"] then
|
2015-08-27 21:27:24 +02:00
|
|
|
local mime = require("mime.core");
|
2015-04-06 08:25:42 +02:00
|
|
|
return (mime.b64(s));
|
|
|
|
|
else
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.base64_alex";
|
2015-04-06 08:25:42 +02:00
|
|
|
return base64.enc(s);
|
|
|
|
|
end
|
2013-01-19 01:16:01 +01:00
|
|
|
end
|
|
|
|
|
|
2015-03-31 20:48:00 +02:00
|
|
|
--decode a base64 string and return a string
|
|
|
|
|
function base64.decode(s)
|
2015-04-06 08:25:42 +02:00
|
|
|
if package.loaded["mime"] then
|
2015-08-27 21:27:24 +02:00
|
|
|
local mime = require("mime.core");
|
2015-04-06 08:25:42 +02:00
|
|
|
return (mime.unb64(s));
|
|
|
|
|
else
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.base64_alex";
|
2015-04-06 08:25:42 +02:00
|
|
|
return base64.dec(s);
|
|
|
|
|
end
|
2013-01-19 01:16:01 +01:00
|
|
|
end
|