diff --git a/bindings/README.md b/bindings/README.md index da01865a3..a2faea44d 100644 --- a/bindings/README.md +++ b/bindings/README.md @@ -40,8 +40,12 @@ The `zencode-data-keys-conf` is a file or stream with a newline separated list o 2. zencode script (string -> base64) *newline* 3. keys (json -> base64) *newline* 4. data (json -> base64) *newline* +5. extra (json -> base64) *newline* +6. context (json -> base64) *newline* -Each line should start directly with the base64 string without any prefix and should end with a newline. Anything else will likely be rejected. +Each line should start directly with the base64 string without any prefix and should end with a newline. + +Empty lines can be a newline (or CRLF) and will be skipped, but should never be omitted: the zencode-exec expects 6 input lines in total, not less, including empty ones, all newline terminated. This executes and returns two streams: 1. `stdout` with the `json` formatted results of the execution diff --git a/src/zen_parse.c b/src/zen_parse.c index 91e2aee44..281bdbafe 100644 --- a/src/zen_parse.c +++ b/src/zen_parse.c @@ -191,6 +191,11 @@ static int lua_unserialize_json(lua_State* L) { return 0; } +// removed because of unexplained segfault when used inside pcall to +// parse zencode: set_rule and set_scenario will explode, also seems +// to perform worse than pure Lua (see PR #709) + +#if 0 char* strtok_single(char* str, char const* delims) { static char* src = NULL; @@ -249,6 +254,7 @@ static int lua_strtok(lua_State* L) { } return 1; } +#endif void zen_add_parse(lua_State *L) { // override print() and io.write() @@ -258,7 +264,6 @@ void zen_add_parse(lua_State *L) { {"trim", lua_trim_spaces}, {"trimq", lua_trim_quotes}, {"jsontok", lua_unserialize_json}, -// {"strtok", lua_strtok}, {NULL, NULL} }; lua_getglobal(L, "_G"); luaL_setfuncs(L, custom_parser, 0); // for Lua versions 5.2 or greater diff --git a/test/zencode/zencode_exec.bats b/test/zencode/zencode_exec.bats index 0c3c44926..c62b00e53 100644 --- a/test/zencode/zencode_exec.bats +++ b/test/zencode/zencode_exec.bats @@ -14,12 +14,11 @@ EOF echo >> zencode_exec_stdin # data echo >> zencode_exec_stdin # extra echo >> zencode_exec_stdin # context - echo >> zencode_exec_stdin cat zencode_exec_stdin | ${TR}/zencode-exec > $TMP/out save_output empty.json } -@test "Execute zencode-exec with all stdin inputs" { +@test "Execute zencode-exec with keys and data stdin inputs" { # empty conf echo > zencode_exec_stdin @@ -120,3 +119,79 @@ EOF save_output trace.json assert_output '["Given nothing","When I create the random object of '"'"'256'"'"' bits","and debug"]' } + +@test "Execute zencode-exec with all stdin inputs including extra" { + + # empty conf + echo > zencode_exec_stdin + + # zencode + cat <> zencode_exec_stdin +rule check version 3.0.0 +Scenario 'ecdh': Bob verifies the signature from Alice +# Here we load the pubkey we'll verify the signature against +Given I have a 'public key' from 'Alice' +# Here we load the objects to be verified +Given I have a 'string' named 'myMessage' +Given I have a 'string array' named 'myStringArray' + +# Here we load the objects's signatures +Given I have a 'signature' named 'myStringArray.signature' +Given I have a 'signature' named 'myMessage.signature' + +# Here we perform the verifications +When I verify the 'myMessage' has a ecdh signature in 'myMessage.signature' by 'Alice' +When I verify the 'myStringArray' has a ecdh signature in 'myStringArray.signature' by 'Alice' + +# Here we print out the result: if the verifications succeeded, a string will be printed out +# if the verifications failed, Zenroom will throw an error +Then print the string 'Zenroom certifies that signatures are all correct!' +Then print the 'myMessage' + +EOF + echo >> zencode_exec_stdin + + # keys + cat <> zencode_exec_stdin +{ + "Alice": { + "public_key": "BBCQg21VcjsmfTmNsg+I+8m1Cm0neaYONTqRnXUjsJLPa8075IYH+a9w2wRO7rFM1cKmv19Igd7ntDZcUvLq3xI=" + } +} +EOF + echo >> zencode_exec_stdin + + # data + cat <> zencode_exec_stdin +{ + "myMessage": "Dear Bob, your name is too short, goodbye - Alice.", + "myMessage.signature": { + "r": "vWerszPubruWexUib69c7IU8Dxy1iisUmMGC7h7arDw=", + "s": "nSjxT+JAP56HMRJjrLwwB6kP+mluYySeZcG8JPBGcpY=" + } +} +EOF + + # extra +cat <> zencode_exec_stdin +{ + "myStringArray": [ + "Hello World! This is my string array, element [0]", + "Hello World! This is my string array, element [1]", + "Hello World! This is my string array, element [2]" + ], + "myStringArray.signature": { + "r": "B8qrQqYSWaTf5Q16mBCjY1tfsD4Cf6ZSMJTHCCV8Chg=", + "s": "S1/Syca6+XozVr5P9fQ6/AkQ+fJTMfwc063sbKmZ5B4=" + } +} +EOF + echo >> zencode_exec_stdin + + # empty context + echo >> zencode_exec_stdin + + cat zencode_exec_stdin | ${TR}/zencode-exec > $TMP/out + save_output verified.json + assert_output '{"myMessage":"Dear Bob, your name is too short, goodbye - Alice.","output":["Zenroom_certifies_that_signatures_are_all_correct!"]}' +}