Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
530f4a67
Commit
530f4a67
authored
10 years ago
by
Konstantin Osipov
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/gh-367-add-module-base64'
parents
6ac6d8cd
3199c132
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/lua/box_net_box.lua
+2
-15
2 additions, 15 deletions
src/lua/box_net_box.lua
src/lua/digest.lua
+35
-0
35 additions, 0 deletions
src/lua/digest.lua
test/box/digest.result
+40
-0
40 additions, 0 deletions
test/box/digest.result
test/box/digest.test.lua
+12
-0
12 additions, 0 deletions
test/box/digest.test.lua
with
89 additions
and
15 deletions
src/lua/box_net_box.lua
+
2
−
15
View file @
530f4a67
...
...
@@ -39,12 +39,6 @@ local GREETING_SIZE = 128
local
TIMEOUT_INFINITY
=
500
*
365
*
86400
ffi
.
cdef
[[
int base64_decode(const char *in_base64, int in_len,
char *out_bin, int out_len);
]]
local
sequence_mt
=
{
__serialize
=
'sequence'
}
local
mapping_mt
=
{
__serialize
=
'mapping'
}
...
...
@@ -75,13 +69,6 @@ local function strxor(s1, s2)
return
res
end
local
function
b64decode
(
str
)
local
so
=
ffi
.
new
(
'char[?]'
,
string.len
(
str
)
*
2
);
local
len
=
ffi
.
C
.
base64_decode
(
str
,
string.len
(
str
),
so
,
string.len
(
str
)
*
2
)
return
ffi
.
string
(
so
,
len
)
end
local
function
keyfy
(
v
)
if
type
(
v
)
==
'table'
then
return
v
...
...
@@ -215,7 +202,7 @@ local proto = {
auth
=
function
(
sync
,
user
,
password
,
handshake
)
local
saltb64
=
string.sub
(
handshake
,
65
)
local
salt
=
string.sub
(
b
64decode
(
saltb64
),
1
,
20
)
local
salt
=
string.sub
(
digest
.
base
64
_
decode
(
saltb64
),
1
,
20
)
local
hpassword
=
digest
.
sha1
(
password
)
local
hhpassword
=
digest
.
sha1
(
hpassword
)
...
...
@@ -228,7 +215,7 @@ local proto = {
)
end
,
b64decode
=
b
64decode
,
b64decode
=
digest
.
base
64
_
decode
,
}
...
...
This diff is collapsed.
Click to expand it.
src/lua/digest.lua
+
35
−
0
View file @
530f4a67
...
...
@@ -25,6 +25,10 @@ ffi.cdef[[
typedef uint32_t (*crc32_func)(uint32_t crc,
const unsigned char *buf, unsigned int len);
extern crc32_func crc32_calc;
/* base64 */
int base64_decode(const char *in_base64, int in_len, char *out_bin, int out_len);
int base64_encode(const char *in_bin, int in_len, char *out_base64, int out_len);
]]
local
ssl
...
...
@@ -67,6 +71,37 @@ local function tohex(r, size)
end
local
m
=
{
base64_encode
=
function
(
bin
)
if
bin
==
nil
then
error
(
'Usage: base64.encode(str)'
)
else
-- note: need add check size of bin, bin might containe any binary data
if
type
(
bin
)
==
'string'
then
local
blen
=
string.len
(
bin
)
local
slen
=
math.ceil
(
blen
*
4
/
3
)
+
2
local
so
=
ffi
.
new
(
'char[?]'
,
slen
)
local
len
=
ffi
.
C
.
base64_encode
(
bin
,
blen
,
so
,
slen
)
bin
=
ffi
.
string
(
so
,
len
)
else
bin
=
''
end
end
return
bin
end
,
base64_decode
=
function
(
data
)
if
type
(
data
)
~=
'string'
then
data
=
''
else
local
slen
=
string.len
(
data
)
local
blen
=
math.ceil
(
slen
*
3
/
4
)
local
bo
=
ffi
.
new
(
'char[?]'
,
blen
)
local
len
=
ffi
.
C
.
base64_decode
(
data
,
slen
,
bo
,
blen
)
data
=
ffi
.
string
(
bo
,
len
)
end
return
data
end
,
crc32
=
function
(
str
)
if
str
==
nil
then
str
=
''
...
...
This diff is collapsed.
Click to expand it.
test/box/digest.result
+
40
−
0
View file @
530f4a67
...
...
@@ -149,6 +149,46 @@ digest.crc32_update(digest.crc32('abc'), 'cde')
---
- 3628146660
...
digest.base64_encode('12345')
---
- MTIzNDU=
...
digest.base64_decode('MTIzNDU=')
---
- '12345'
...
digest.base64_encode('asdfl asdf adfa zxc vzxcvz llll')
---
- YXNkZmwgYXNkZiBhZGZhIHp4YyB2enhjdnogbGxsbA==
...
digest.base64_decode('YXNkZmwgYXNkZiBhZGZhIHp4YyB2enhjdnogbGxsbA==')
---
- asdfl asdf adfa zxc vzxcvz llll
...
digest.base64_encode('11 00 11 00 abcdef ABCDEF 00 11 00 11')
---
- MTEgMDAgMTEgMDAgYWJjZGVmIEFCQ0RFRiAwMCAxMSAwMCAxMQ==
...
digest.base64_decode('MTEgMDAgMTEgMDAgYWJjZGVmIEFCQ0RFRiAwMCAxMSAwMCAxMQ==')
---
- 11 00 11 00 abcdef ABCDEF 00 11 00 11
...
digest.base64_decode(nil)
---
-
...
digest.base64_encode(nil)
---
- error: 'builtin/digest.lua:76: Usage: base64.encode(str)'
...
digest.base64_encode(123)
---
-
...
digest.base64_decode(123)
---
-
...
digest = nil
---
...
This diff is collapsed.
Click to expand it.
test/box/digest.test.lua
+
12
−
0
View file @
530f4a67
...
...
@@ -43,4 +43,16 @@ digest.crc32_update(4294967295, 'abc')
digest
.
crc32
(
'abccde'
)
digest
.
crc32_update
(
digest
.
crc32
(
'abc'
),
'cde'
)
digest
.
base64_encode
(
'12345'
)
digest
.
base64_decode
(
'MTIzNDU='
)
digest
.
base64_encode
(
'asdfl asdf adfa zxc vzxcvz llll'
)
digest
.
base64_decode
(
'YXNkZmwgYXNkZiBhZGZhIHp4YyB2enhjdnogbGxsbA=='
)
digest
.
base64_encode
(
'11 00 11 00 abcdef ABCDEF 00 11 00 11'
)
digest
.
base64_decode
(
'MTEgMDAgMTEgMDAgYWJjZGVmIEFCQ0RFRiAwMCAxMSAwMCAxMQ=='
)
digest
.
base64_decode
(
nil
)
digest
.
base64_encode
(
nil
)
digest
.
base64_encode
(
123
)
digest
.
base64_decode
(
123
)
digest
=
nil
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment