61 lines
1.4 KiB
Lua
61 lines
1.4 KiB
Lua
local b64 = require("ssso_base64")
|
|
|
|
local class__identity = {}
|
|
|
|
function class__identity:build(user, password, name, email)
|
|
local identity = {
|
|
u = user,
|
|
p = password,
|
|
n = name,
|
|
e = email,
|
|
}
|
|
setmetatable(identity, {__index = self})
|
|
return identity
|
|
end
|
|
|
|
function class__identity:serialize() -- TODO: test
|
|
return (self.u or "\025")
|
|
.. "\031" .. (self.p or "\025")
|
|
.. "\031" .. (self.n or "\025")
|
|
.. "\031" .. (self.e or "\025")
|
|
end
|
|
|
|
function class__identity:deserialize(ser) -- TODO: test
|
|
local identity
|
|
ser:gsub("^(.-)\031(.-)\031(.-)\031(.*)", function (u, p, n, e)
|
|
if u == "\025" then u = nil end
|
|
if p == "\025" then p = nil end
|
|
if n == "\025" then n = nil end
|
|
if e == "\025" then e = nil end
|
|
identity = self:build(u, p, n, e)
|
|
end)
|
|
return identity
|
|
end
|
|
|
|
function class__identity:format(template)
|
|
local s = template
|
|
s = s:gsub("\ru%.", self.u or "")
|
|
s = s:gsub("\rp%.", self.p or "")
|
|
s = s:gsub("\rn%.", self.n or "")
|
|
s = s:gsub("\re%.", self.e or "")
|
|
s = s:gsub("\rb64%(([^\r]-)%)%.", function(x) return b64.encode_base64(x) end)
|
|
s = s:gsub("\ru64%(([^\r]-)%)%.", function(x) return b64.encode_base64url(x) end)
|
|
return s
|
|
end
|
|
|
|
function class__identity:email()
|
|
return self.e
|
|
end
|
|
|
|
function class__identity:name()
|
|
return self.n
|
|
end
|
|
|
|
function class__identity:user()
|
|
return self.u
|
|
end
|
|
|
|
return {
|
|
class__identity = class__identity,
|
|
}
|