commit e9a32808a843e703fa37808406e8727257e0872e
parent 72a51a39b92f5fdbebe419a8d1520069c87324fc
Author: lash <dev@holbrook.no>
Date: Mon, 15 Apr 2024 20:02:40 +0100
Implement asn1/der encoded testdata generation
Diffstat:
11 files changed, 41 insertions(+), 246 deletions(-)
diff --git a/Makefile b/Makefile
@@ -21,7 +21,10 @@ debug: gtk all
G_DEBUG=all G_MESSAGES_DEBUG=all gdb ./src/gtk/a.out
#test: gtk all test_src test_gtk
-test: test_src test_gtk
+test: testdata test_src test_gtk
+
+testdata_schema:
+ asn1ate src/schema_entry_head.txt > testdata_asn1schema.py
test_src: all
make -C src/tests test
@@ -29,9 +32,10 @@ test_src: all
test_gtk: gtk all
make -C src/gtk/tests test
-testdata:
+testdata: testdata_schema
rm -vrf testdata_mdb
- python testdata.py
+ #python testdata.py
+ python testdata_asn1.py
doc:
pandoc -fgfm -tplain README.md > README
diff --git a/README.md b/README.md
@@ -32,6 +32,7 @@ The code expects objects from these source trees to be available somehow:
|project | upstream source | version | tar.gz sha256 |
|---|---|---|---|
+| liblash | [https://holbrook.no/src/liblash](https://holbrook.no/src/liblash) `(4e704929297371934cb5ace5fb59433f6c664c34)` | `0.1.0` | `15d90c518626eac4333e3fa8a02e4bcf16cce31e99e6c6668cc2e4ca44691cd3` |
| varint.c | [https://github.com/tidwall/varint.c](https://github.com/tidwall/varint.c) `(7e1f7067eaf6ee114d865c99a8f5f01c813f3a61)` | `0.1.0` | `e33f83a8cd965827554c134bcb607990c04c0097cd57e49ae8c343c6d311826f` |
| libcmime | [https://github.com/spmfilter/libcmime.git](https://github.com/spmfilter/libcmime.git) `(dd21eb096d162656e30243f60fc4bc35ad39ae6e)` | `0.2.2` | `18a8d46ebec575a79212acc2dc6af7fd7bdeba3a9b85a70677ed0b7785c5c04e` |
| gst-plugins-rs | [https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs](https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs) `(a84bbc66f30573b62871db163c48afef75adf6ec)` | `1.22.10 (gstreamer)` | `691d5d52f59ec6322a2f6ddc1039ef47c9ac5e6328e2df1ef920629b46c659df` |
diff --git a/requirements.txt b/requirements.txt
@@ -2,3 +2,5 @@ varint~=1.0.2
lmdb~=1.4.0
faker~=24.0.0
pycryptodome==3.20.0
+asn1ate~=0.6
+pyasn1~=0.5.0
diff --git a/src/Makefile b/src/Makefile
@@ -1,8 +1,8 @@
OBJS := $(patsubst %.c,%.o,$(filter-out main.c,$(wildcard *.c)))
INCLUDES := `pkg-config --cflags libgcrypt lmdb libxdg-basedir`
#CFLAGS += $(INCLUDES) -g3 -Wall -Iaux/varint
-CFLAGS += $(INCLUDES) -g3 -Wall
-LIBS := `pkg-config --libs libgcrypt zlib lmdb libxdg-basedir` -lb64 -lvarint
+CFLAGS += $(INCLUDES) -Wall
+LIBS := `pkg-config --libs libgcrypt zlib lmdb libxdg-basedir` -lb64 -lvarint -llash
LDFLAGS += $(LIBS)
#all: aux resource $(OBJS)
diff --git a/src/endian.c b/src/endian.c
@@ -1,44 +0,0 @@
-#include "endian.h"
-
-int is_le() {
- unsigned short s = 42;
- return *((unsigned char*)&s) == 42;
-}
-
-// convert unsigned integer to little-endian representation
-int to_endian(char direction, int l, void *n) {
- union le un;
-
- if (l == 1 || is_le() == direction) {
- return 0;
- }
- switch(l) {
- case sizeof(long long):
- un.ll = (long long*)n;
- break;
- case sizeof(int):
- un.i = (int*)n;
- break;
- case sizeof(short):
- un.s = (short*)n;
- break;
- default:
- return 1;
- }
- flip_endian(l, &un);
-
- return 0;
-}
-
-void flip_endian(int l, union le *n) {
- int i;
- char t;
- unsigned char *ne;
-
- ne = (n->c)+(l-1);
- for (i = 0; i < l/2; i++) {
- t = *(n->c+i);
- *((n->c)+i) = *(ne-i);
- *(ne-i) = t;
- }
-}
diff --git a/src/endian.h b/src/endian.h
@@ -1,45 +0,0 @@
-#ifndef LASH_ENDIAN_H_
-#define LASH_ENDIAN_H_
-
-/**
- *
- * \brief Encapsulats all suppoerted integer lengths for endian conversion.
- *
- */
-union le {
- short *s;
- int *i;
- long long *ll;
- unsigned char *c;
-};
-
-//int le(int l, void *n);
-/*
- * Return true (1) if system is little-endian.
- */
-int is_le();
-/**
- * Convert to specified endian order.
- *
- * The integer data in \c n is changed in-place.
- *
- * If \c direction is same as system endianness, or \c l==1, no action is taken.
- *
- * \param direction 0 for big-endian, 1 for little-endian.
- * \param l Length of integer \c n in bytes.
- * \param n Integer data.
- * \return 1 if \c l is invalid byte size, 0 (success) otherwise.
- *
- */
-int to_endian(char direction, int l, void *n);
-/**
- * Change endian order of given number.
- *
- * The integer data in \c n is changed in-place.
- *
- * \param l Length of integer \c in bytes.
- * \param n Integer data.
- */
-void flip_endian(int l, union le *n);
-
-#endif // LASH_ENDIAN_H_
diff --git a/src/export.c b/src/export.c
@@ -1,114 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <varint.h>
-
-#include "export.h"
-#include "common.h"
-#include "err.h"
-
-
-int export_init(struct kee_export *ex, size_t count) {
- size_t unit;
-
- ex->count = count;
-
- // 10 is max varint
- unit = sizeof(ex->lenlens) + sizeof(ex->data) + sizeof(ex->datalens) + 10;
- ex->lens = malloc(unit * count);
- if (ex->lens == NULL) {
- return 1;
- }
- unit += sizeof(ex->lens) * count;
- ex->lenlens = (size_t*)ex->lens + unit;
- unit += sizeof(ex->lenlens) * count;
- ex->data = (char**)ex->lens + unit;
- unit += sizeof(ex->data) * count;
- ex->datalens = (size_t*)ex->lens + unit;
- return ERR_OK;
-}
-
-int export_add_item(struct kee_export *ex, char *in, size_t in_len) {
- int r;
- char b[10];
-
- if (in_len == 0) {
- return ERR_FAIL;
- }
-
- r = 0;
- r += varint_write_u(b, in_len);
- memcpy(ex->lens+(ex->count*10), b, 10);
- *(ex->lenlens + sizeof(ex->lenlens) * ex->count) = (size_t)r;
- *(ex->datalens + sizeof(ex->datalens) * ex->count) = in_len;
- *(ex->data + sizeof(ex->data) * ex->count) = in;
-
- ex->size += r;
- ex->count++;
- return r;
-
-}
-
-int export_write(struct kee_export *ex, char *out, size_t out_len) {
- char *p;
- int i;
- size_t l;
- size_t c;
-
- if (out_len < ex->size) {
- return -1;
- }
-
- p = out;
- c = 0;
- for (i = 0; i < ex->count; i++) {
- l = ex->lenlens[i];
- memcpy(p, ex->lens+(10*i), l);
- p += l;
- c += l;
- l = ex->datalens[i];
- memcpy(p, ex->data[i], l);
- p += l;
- c += l;
- }
- return c;
-}
-
-
-void export_free(struct kee_export *ex) {
- free(ex->lens);
-}
-
-// data not copied, must be in scope for duration
-int import_init(struct kee_import *im, const char *in, size_t in_len) {
- im->data = (char*)in;
- im->size = in_len;
- im->crsr = 0;
- im->eof = 0;
- return ERR_OK;
-}
-
-kee_boolean done(struct kee_import *im) {
- return im->eof;
-}
-
-int import_read(struct kee_import *im, char *out, size_t out_len) {
- int r;
- uint64_t l;
-
- if (im->size - im->crsr <= 0) {
- im->eof = 1;
- return 0;
- }
-
- r = varint_read_u(im->data + im->crsr, out_len, &l);
- im->crsr += r;
-
- memcpy(out, im->data + im->crsr, (size_t)l);
- im->crsr += l;
-
- return l;
-}
-
-void import_free(struct kee_import *im) {
-}
diff --git a/src/export.h b/src/export.h
@@ -1,36 +0,0 @@
-#ifndef _EXPORT_H
-#define _EXPORT_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "common.h"
-
-struct kee_export {
- size_t cap;
- int count;
- size_t size;
- char *lens;
- size_t *lenlens;
- char **data;
- size_t *datalens;
-};
-
-struct kee_import {
- char *data;
- size_t size;
- unsigned int crsr;
- kee_boolean eof;
-};
-
-int export_init(struct kee_export *ex, size_t count);
-void export_free(struct kee_export *ex);
-int export_add_item(struct kee_export *ex, char *in, size_t in_len);
-int export_write(struct kee_export *ex, char *out, size_t out_len);
-
-int import_init(struct kee_import *im, const char *in, size_t in_len);
-void import_free(struct kee_import *im);
-int import_read(struct kee_import *im, char *out, size_t out_len);
-kee_boolean done(struct kee_import *im);
-
-#endif // _EXPORT_H
diff --git a/src/gtk/Makefile b/src/gtk/Makefile
@@ -4,7 +4,7 @@ INCLUDES := -I.. -I../aux/include
#CFLAGS += `pkg-config --cflags gtk4 gstreamer-1.0 libcmime` $(INCLUDES) -g3 -Wall
CFLAGS += `pkg-config --cflags gtk4 gstreamer-1.0 ` $(INCLUDES) -g3 -Wall
#LIBS := `pkg-config --libs gtk4 zlib lmdb libgcrypt libxdg-basedir gstreamer-1.0 libcmime` -lb64
-LIBS := `pkg-config --libs gtk4 zlib lmdb libgcrypt libxdg-basedir gstreamer-1.0` -lb64 -lcmime -lvarint
+LIBS := `pkg-config --libs gtk4 zlib lmdb libgcrypt libxdg-basedir gstreamer-1.0` -lb64 -lcmime -lvarint -llash
LDFLAGS += $(LIBS)
all: resource $(OBJS)
diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c
@@ -4,13 +4,15 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <tasn1.h>
+
#include "cmime.h"
#include "varint.h"
#include "kee-entry.h"
#include "db.h"
#include "err.h"
-#include "export.h"
+//#include "export.h"
#include "hex.h"
#include "cadiz.h"
#include "db.h"
diff --git a/src/schema_entry_head.txt b/src/schema_entry_head.txt
@@ -0,0 +1,25 @@
+Kee DEFINITIONS EXPLICIT TAGS ::= BEGIN
+ KeeEntryHead ::= SEQUENCE {
+ uoa UTF8String,
+ uoaDecimals INTEGER,
+ alicePubKey OCTET STRING,
+ bobPubKey OCTET STRING,
+ body OCTET STRING
+ }
+
+ KeeEntryFlags ::= BIT STRING {
+ bob-is-signer(0)
+ }
+
+ KeeEntry ::= SEQUENCE {
+ parent OCTET STRING,
+--- timestamp GeneralizedTime,
+ timestamp INTEGER,
+ aliceCreditDelta INTEGER,
+ aliceCollateralDelta INTEGER,
+ bobCreditDelta INTEGER,
+ bobCollateralDelta INTEGER,
+ flags KeeEntryFlags,
+ body OCTET STRING
+ }
+END