Commit fec66a1c authored by Jaromil's avatar Jaromil
Browse files

zencode pack with simple msgpack encoding statements in when

parent 89247e0e
......@@ -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
......
--[[
--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
......@@ -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")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment