kee

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

commit a9c7318ab19afd21d509d52def1fb42f44dc674c
parent afb77164ac5170cd713ff5b94db1d76855ada1e4
Author: lash <dev@holbrook.no>
Date:   Sat, 20 Apr 2024 09:59:44 +0100

Implement resolve method for ledger

Diffstat:
Msrc/content.c | 3++-
Msrc/content.h | 5+++--
Msrc/ledger.c | 107+++++++++----------------------------------------------------------------------
Msrc/ledger.h | 2++
Msrc/tests/content.c | 2+-
Msrc/tests/ledger.c | 5+++++
Asrc/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad | 7+++++++
Asrc/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 | 7+++++++
8 files changed, 38 insertions(+), 100 deletions(-)

diff --git a/src/content.c b/src/content.c @@ -37,7 +37,7 @@ int kee_content_resolve(struct kee_content_t *content, Cadiz *cadiz) { r = cadiz_resolve(cadiz, content->key, content->body, &c); if (!r) { content->mem_size -= c; - content->flags |= KEE_CONTENT_RESOLVED_BODY; + content->flags |= KEE_CONTENT_RESOLVED_DATA; msg = cmime_message_new(); r = cmime_message_from_string(&msg, content->body, 0); if (!r) { @@ -50,6 +50,7 @@ int kee_content_resolve(struct kee_content_t *content, Cadiz *cadiz) { content->flags |= KEE_CONTENT_RESOLVED_SUBJECT; content->mem_size -= subject_len; } + content->flags |= KEE_CONTENT_RESOLVED_BODY; } cmime_message_free(msg); } diff --git a/src/content.h b/src/content.h @@ -9,8 +9,9 @@ #define KEE_CONTENT_KEY_SIZE 64 #define KEE_CONTENT_RESOLVED 1 -#define KEE_CONTENT_RESOLVED_BODY 2 -#define KEE_CONTENT_RESOLVED_SUBJECT 4 +#define KEE_CONTENT_RESOLVED_DATA 2 +#define KEE_CONTENT_RESOLVED_BODY 4 +#define KEE_CONTENT_RESOLVED_SUBJECT 8 struct kee_content_t { char key[KEE_CONTENT_KEY_SIZE]; diff --git a/src/ledger.c b/src/ledger.c @@ -15,11 +15,6 @@ extern const asn1_static_node schema_entry_asn1_tab[]; -int kee_ledger_resolve(struct kee_ledger_t *ledger, struct Cadiz *resolver) { - return ERR_OK; -} - - static char *get_message(asn1_node item, char *out_digest, char *out_data, size_t *out_len) { int r; size_t c; @@ -295,7 +290,7 @@ struct kee_ledger_item_t *kee_ledger_parse_item(struct kee_ledger_t *ledger, con if (r != ASN1_SUCCESS) { return NULL; } - r = kee_content_init(&(ledger->content), tmp, 0); + r = kee_content_init(&(cur->content), tmp, 0); if (r) { return NULL; } @@ -342,11 +337,6 @@ int kee_ledger_parse(struct kee_ledger_t *ledger, const char *data, size_t data_ return r; } -// r = calculate_digest_algo(data, data_len, o->current_id, GCRY_MD_SHA512); -// if (r) { -// return ERR_DIGESTFAIL; -// } - c = 64; r = asn1_read_value(item, "uoa", ledger->uoa, &c); if (r != ASN1_SUCCESS) { @@ -385,88 +375,13 @@ int kee_ledger_parse(struct kee_ledger_t *ledger, const char *data, size_t data_ return ERR_OK; } -// -//int kee_ledger_parse_item(kee_ledger_item_t *item, const char *data, size_t data_len) { -// int r; -// char err[1024]; -// asn1_node root; -// asn1_node item; -// int alice; -// int bob; -// int credit; -// int collateral; -// int c; -// char flag; -// int v; -// char *p; -// -// memset(&root, 0, sizeof(root)); -// memset(&item, 0, sizeof(item)); -// r = asn1_array2tree(schema_entry_asn1_tab, &root, err); -// if (r != ASN1_SUCCESS) { -// debug_log(DEBUG_ERROR, err); -// return ERR_FAIL; -// } -// -// r = asn1_create_element(root, "Kee.KeeEntry", &item); -// if (r != ASN1_SUCCESS) { -// fprintf(stderr, "%s\n", err); -// return r; -// } -// -// c = (int)data_len - 1; -// r = asn1_der_decoding(&item, data, c, err); -// if (r != ASN1_SUCCESS) { -// fprintf(stderr, "%s\n", err); -// return r; -// } -// flag = *(data+data_len-1); -// -//// c = 1; -//// flags = 0; -//// r = asn1_read_value(item, "flags", &flags, &c); -//// if (r != ASN1_SUCCESS) { -//// fprintf(stderr, "%s\n", err); -//// return r; -//// } -// -// credit = 0; -// p = (char*)&v; -// c = sizeof(v); -// v = 0; -// r = asn1_read_value(item, "creditDelta", p, &c); -// if (r != ASN1_SUCCESS) { -// fprintf(stderr, "%s\n", err); -// return r; -// } -// -// strap_be(p, c, (char*)&credit, sizeof(credit)); -// if (is_le()) { -// flip_endian(sizeof(credit), (void*)&credit); -// } -// -// collateral = 0; -// c = sizeof(v); -// v = 0; -// r = asn1_read_value(item, "collateralDelta", p, &c); -// if (r != ASN1_SUCCESS) { -// fprintf(stderr, "%s\n", err); -// return r; -// } -// -// strap_be(p, c, (char*)&collateral, sizeof(collateral)); -// if (is_le()) { -// flip_endian(sizeof(collateral), (void*)&collateral); -// } -// -// -// alice = 0; -// bob = 0; -// if (flag) { // bit string is left to right -// bob = credit; -// } else { -// alice = credit; -// } -// -// return ERR_OK; -//} +void kee_ledger_resolve(struct kee_ledger_t *ledger, Cadiz *cadiz) { + struct kee_ledger_item_t *item; + + kee_content_resolve(&ledger->content, cadiz); + item = ledger->last_item; + while (item != NULL) { + kee_content_resolve(&item->content, cadiz); + item = item->prev_item; + } +} diff --git a/src/ledger.h b/src/ledger.h @@ -4,6 +4,7 @@ #include <time.h> #include "content.h" +#include "cadiz.h" enum kee_initiator { ALICE, @@ -35,5 +36,6 @@ struct kee_ledger_item_t *kee_ledger_parse_item(struct kee_ledger_t *ledger, con int kee_ledger_parse(struct kee_ledger_t *ledger, const char *data, size_t data_len); void kee_ledger_free(struct kee_ledger_t *ledger); void kee_ledger_item_free(struct kee_ledger_item_t *item); +void kee_ledger_resolve(struct kee_ledger_t *ledger, Cadiz *cadiz); #endif diff --git a/src/tests/content.c b/src/tests/content.c @@ -42,7 +42,7 @@ int main() { return 1; } - if (content.flags != (KEE_CONTENT_RESOLVED_SUBJECT | KEE_CONTENT_RESOLVED_BODY | KEE_CONTENT_RESOLVED)) { + if (content.flags != (KEE_CONTENT_RESOLVED_SUBJECT | KEE_CONTENT_RESOLVED_BODY | KEE_CONTENT_RESOLVED_DATA | KEE_CONTENT_RESOLVED)) { return 1; } diff --git a/src/tests/ledger.c b/src/tests/ledger.c @@ -16,8 +16,11 @@ int main() { struct kee_ledger_t ledger; struct kee_ledger_item_t *ledger_item_a; struct kee_ledger_item_t *ledger_item_b; + Cadiz cadiz; char data[1024]; + cadiz.locator = "./testdata_resource"; + c = hex2bin(test_ledger_data, (unsigned char*)data); r = kee_ledger_parse(&ledger, data, c); if (r) { @@ -36,6 +39,8 @@ int main() { return 1; } + kee_ledger_resolve(&ledger, &cadiz); + kee_ledger_free(&ledger); return 0; diff --git a/src/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad b/src/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad @@ -0,0 +1,7 @@ +Subject: Opportunity price prove nature system recent live. +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable +MIME-Version: 1.0 + +Listen place sport air. His product college. Hundred today perform technology= + challenge tree. diff --git a/src/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 b/src/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 @@ -0,0 +1,7 @@ +Subject: Receive enter personal develop. +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable +MIME-Version: 1.0 + +Half example bar ready none possible all. Carry field respond. Peace law acti= +vity right remain operation people.