kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit 927132e4aa022fc30de410894493c10af3b6c54c
parent a81d82240e90aacb97818b8b3f580102933b3bed
Author: lash <dev@holbrook.no>
Date:   Sat, 27 Apr 2024 22:07:02 +0100

Test verify ledger item message generator

Diffstat:
Msrc/tests/transport.c | 26++++++++++++++++++++++++++
Msrc/transport.c | 17+++++++++++++----
Msrc/transport.h | 2+-
3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/tests/transport.c b/src/tests/transport.c @@ -75,6 +75,10 @@ int test_msg() { char *p; size_t c; struct kee_test_t t; + struct kee_transport_t ledger_transport; + struct kee_transport_t item_transport; + char out[1024]; + size_t out_len; r = kee_test_generate(&t); if (r) { @@ -85,11 +89,33 @@ int test_msg() { if (c == 0) { return 1; } + r = kee_transport_single(&ledger_transport, KEE_TRANSPORT_RAW, KEE_CMD_LEDGER, t.ledger_bytes_len); + if (r) { + return 1; + } + r = kee_transport_write(&ledger_transport, t.ledger_bytes, t.ledger_bytes_len); + if (r) { + return 1; + } c = kee_test_get_ledger_item_data(&t, 0, &p); if (c == 0) { return 1; } + r = kee_transport_single(&item_transport, KEE_TRANSPORT_RAW, KEE_CMD_DELTA, t.ledger_item_bytes_len); + if (r) { + return 1; + } + r = kee_transport_write(&item_transport, t.ledger_item_bytes, t.ledger_item_bytes_len); + if (r) { + return 1; + } + + out_len = 1024; + r = kee_transport_encode_ledger(&ledger_transport, &item_transport, out, &out_len); + if (r) { + return 1; + } kee_test_free(&t); diff --git a/src/transport.c b/src/transport.c @@ -256,11 +256,13 @@ enum kee_cmd_e kee_transport_cmd(struct kee_transport_t *trans) { return *trans->cmd & 0x1f; } -int kee_transport_encode_ledger(struct kee_transport_t *trans_ledger, struct kee_transport_t *trans_item, char *out, size_t out_len) { +int kee_transport_encode_ledger(struct kee_transport_t *trans_ledger, struct kee_transport_t *trans_item, char *out, size_t *out_len) { int r; char *p; unsigned short part_length; + size_t l; + *out_len = 0; *out = 0; p = out + 1; part_length = (unsigned short)trans_ledger->chunker.data_len; @@ -268,18 +270,25 @@ int kee_transport_encode_ledger(struct kee_transport_t *trans_ledger, struct kee if (r) { return ERR_FAIL; } - memcpy(p, &part_length, sizeof(unsigned short)); + l = sizeof(unsigned short); + memcpy(p, &part_length, l); p += sizeof(unsigned short); + *out_len += l; memcpy(p, trans_ledger->chunker.data, trans_ledger->chunker.data_len); + p += trans_ledger->chunker.data_len; + *out_len += trans_ledger->chunker.data_len; part_length = (unsigned short)trans_item->chunker.data_len; r = to_endian(TO_ENDIAN_BIG, 2, &part_length); if (r) { return ERR_FAIL; } - memcpy(p, &part_length, sizeof(unsigned short)); - p += sizeof(unsigned short); + memcpy(p, &part_length, l); + p += l; + *out_len += l; memcpy(p, trans_item->chunker.data, trans_item->chunker.data_len); + p += trans_item->chunker.data_len; + *out_len += trans_item->chunker.data_len; return ERR_OK; } diff --git a/src/transport.h b/src/transport.h @@ -64,6 +64,6 @@ void kee_transport_set_response(struct kee_transport_t *trans); int kee_transport_import(struct kee_transport_t *trans, enum kee_transport_mode_e mode, const char *data, size_t data_len); int kee_transport_read(struct kee_transport_t *trans, char *out, size_t *out_len); -int kee_transport_encode_ledger(struct kee_transport_t *trans_ledger, struct kee_transport_t *trans_item, char *out, size_t out_len); +int kee_transport_encode_ledger(struct kee_transport_t *trans_ledger, struct kee_transport_t *trans_item, char *out, size_t *out_len); #endif // _KEE_TRANSPORT_H