diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 14:19:26 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 14:19:26 +0200 |
commit | 3ef6719f47b734b12c0b11c725b7f12e3fb3c08a (patch) | |
tree | a635ac65bfc72d126d97e48e22c38ac33343b4f4 /code/test | |
parent | 922e8313f2b3f6157a61b3c867fdc3832bb92a68 (diff) |
fs layout updated
Diffstat (limited to 'code/test')
-rw-r--r-- | code/test/Makefile | 4 | ||||
-rw-r--r-- | code/test/init.c | 36 | ||||
-rw-r--r-- | code/test/init_proxy.c | 42 |
3 files changed, 80 insertions, 2 deletions
diff --git a/code/test/Makefile b/code/test/Makefile index 02ade87..5c25b5e 100644 --- a/code/test/Makefile +++ b/code/test/Makefile @@ -1,6 +1,6 @@ -CFLAGS=-I.. -O3 -Wno-int-to-void-pointer-cast +CFLAGS=-I../core -O3 -Wno-int-to-void-pointer-cast LDFLAGS=-lm -pthread -dep=../libecpcore.a ../crypto/libecpcr.a ../htable/libecpht.a ../posix/libecptr.a ../posix/libecptm.a ../init.o +dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a init.o %.o: %.c $(CC) $(CFLAGS) -c $< diff --git a/code/test/init.c b/code/test/init.c new file mode 100644 index 0000000..7e39f87 --- /dev/null +++ b/code/test/init.c @@ -0,0 +1,36 @@ +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> + +#include "core.h" + +static int v_rng(void *buf, size_t bufsize) { + int fd; + + if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; + size_t nb = read(fd, buf, bufsize); + close(fd); + if (nb != bufsize) return -1; + return 0; +} + +static ECPConnection *conn_alloc(unsigned char type) { + return malloc(sizeof(ECPConnection)); +} + +static void conn_free(ECPConnection *conn) { + free(conn); +} + +int ecp_init(ECPContext *ctx) { + int rv; + + rv = ecp_ctx_create(ctx); + if (rv) return rv; + + ctx->rng = v_rng; + ctx->conn_alloc = conn_alloc; + ctx->conn_free = conn_free; + + return ECP_OK; +}
\ No newline at end of file diff --git a/code/test/init_proxy.c b/code/test/init_proxy.c new file mode 100644 index 0000000..c7f560d --- /dev/null +++ b/code/test/init_proxy.c @@ -0,0 +1,42 @@ +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> + +#include "core.h" +#include "proxy.h" + +static int v_rng(void *buf, size_t bufsize) { + int fd; + + if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; + size_t nb = read(fd, buf, bufsize); + close(fd); + if (nb != bufsize) return -1; + return 0; +} + +static ECPConnection *conn_alloc(unsigned char type) { + switch (type) { + case ECP_CTYPE_PROXYF: + return malloc(sizeof(ECPConnProxyF)); + default: + return malloc(sizeof(ECPConnection)); + } +} + +static void conn_free(ECPConnection *conn) { + free(conn); +} + +int ecp_init(ECPContext *ctx) { + int rv; + + rv = ecp_ctx_create(ctx); + if (rv) return rv; + + ctx->rng = v_rng; + ctx->conn_alloc = conn_alloc; + ctx->conn_free = conn_free; + + return ecp_proxy_init(ctx); +}
\ No newline at end of file |