Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zenroom
Zenroom
Commits
fec66a1c
Commit
fec66a1c
authored
May 11, 2022
by
Jaromil
Browse files
zencode pack with simple msgpack encoding statements in when
parent
89247e0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lua/init.lua
View file @
fec66a1c
...
...
@@ -119,6 +119,7 @@ load_scenario('zencode_dictionary') -- when extension
load_scenario
(
'zencode_verify'
)
-- when extension
load_scenario
(
'zencode_then'
)
load_scenario
(
'zencode_keyring'
)
load_scenario
(
'zencode_pack'
)
-- mpack and zpack
-- this is to evaluate expressions or derivate a column
-- it would execute lua code inside the zencode and is
-- therefore dangerous, switched off by default
...
...
src/lua/zencode_pack.lua
0 → 100644
View file @
fec66a1c
--[[
--This file is part of zenroom
--
--Copyright (C) 2022 Dyne.org foundation
--designed, written and maintained by Denis Roio <jaromil@dyne.org>
--
--This program is free software: you can redistribute it and/or modify
--it under the terms of the GNU Affero General Public License v3.0
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Affero General Public License for more details.
--
--Along with this program you should have received a copy of the
--GNU Affero General Public License v3.0
--If not, see http://www.gnu.org/licenses/agpl.txt
--]]
-- TODO: distinguish zpack and mpack
When
(
"create the mpack of ''"
,
function
(
src
)
empty
'mpack'
local
source
=
have
(
src
)
local
tmp
=
MPACK
.
encode
(
source
)
ACK
.
mpack
=
OCTET
.
from_rawlen
(
tmp
,
#
tmp
)
new_codec
(
'mpack'
,
{
zentype
=
'element'
})
end
)
When
(
"create the '' decoded from mpack ''"
,
function
(
dst
,
src
)
empty
(
dst
)
local
pack
=
have
(
src
)
ZEN
.
assert
(
ZEN
.
CODEC
[
src
].
zentype
==
'element'
,
"Invalid mpack, not an element: "
..
src
)
ZEN
.
assert
(
type
(
pack
)
==
'zenroom.octet'
,
"Invalid mpack, not an octet: "
..
src
)
ACK
[
dst
]
=
MPACK
.
decode
(
OCTET
.
to_string
(
pack
)
)
new_codec
(
dst
)
end
)
\ No newline at end of file
test/zenroom_msgpack.lua
View file @
fec66a1c
...
...
@@ -29,7 +29,11 @@ test = {
test_hash
=
sha256
(
ZEN
.
serialize
(
test
)
):
hex
()
print
(
"ENC SHA256: "
..
test_hash
)
sm
=
MPACK
.
encode
(
test
)
d
=
MPACK
.
decode
(
sm
)
print
(
sm
)
local
ssm
=
OCTET
.
from_rawlen
(
sm
,
#
sm
)
local
b64
=
ssm
:
base64
()
d
=
MPACK
.
decode
(
OCTET
.
from_base64
(
b64
):
string
())
res_hash
=
sha256
(
ZEN
.
serialize
(
d
)
):
hex
()
print
(
"DEC SHA256: "
..
res_hash
)
assert
(
res_hash
==
test_hash
,
"encoding and decoding mismatch"
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment