Commit 7cdc6fa2 authored by Jan Včelák's avatar Jan Včelák 🚀

[dnssec] wire API, remove functions using GnuTLS datum

parent 89f9aefa
......@@ -18,10 +18,10 @@
#include <arpa/inet.h>
#include <assert.h>
#include <gnutls/gnutls.h>
#include <stdint.h>
#include <string.h>
#include "bignum.h"
#include "binary.h"
#include "shared.h"
......@@ -109,13 +109,6 @@ static inline void wire_read_binary(wire_ctx_t *ctx, dnssec_binary_t *data)
wire_read(ctx, data->data, data->size);
}
static inline void wire_read_datum(wire_ctx_t *ctx, gnutls_datum_t *data)
{
assert(data);
wire_read(ctx, data->data, data->size);
}
static inline void wire_available_binary(wire_ctx_t *ctx, dnssec_binary_t *data)
{
assert(ctx);
......@@ -152,38 +145,19 @@ static inline void wire_write(wire_ctx_t *ctx, const uint8_t *data, size_t size)
static inline void wire_write_binary(wire_ctx_t *ctx, const dnssec_binary_t *data)
{
assert(ctx);
assert(data);
wire_write(ctx, data->data, data->size);
}
static inline void wire_write_ralign(wire_ctx_t *ctx, size_t width,
const uint8_t *data, size_t size)
static inline void wire_write_bignum(wire_ctx_t *ctx, size_t width,
const dnssec_binary_t *bignum)
{
assert(ctx);
assert(data);
assert(width >= size);
size_t padding = width - size;
if (padding > 0) {
memset(ctx->position, 0, padding);
ctx->position += padding;
}
wire_write(ctx, data, size);
}
static inline void wire_write_ralign_binary(wire_ctx_t *ctx, size_t width,
const dnssec_binary_t *data)
{
assert(data);
wire_write_ralign(ctx, width, data->data, data->size);
}
assert(bignum);
static inline void wire_write_datum(wire_ctx_t *ctx, gnutls_datum_t *data)
{
assert(data);
wire_write(ctx, data->data, data->size);
dnssec_binary_t dest = { .data = ctx->position, .size = width };
bignum_write(&dest, bignum);
ctx->position += width;
}
......@@ -76,9 +76,10 @@ int main(void)
ok(memcmp(buffer.data + 12, out, 7) == 0 && wire_tell(&wire) == 19,
"wire_write()");
dnssec_binary_t bignum = { .data = (uint8_t *)out, .size = 4 };
const uint8_t expect[8] = { 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1d, 0xca, 0xfe };
wire_seek(&wire, 2);
wire_write_ralign(&wire, 8, out, 4);
wire_write_bignum(&wire, 8, &bignum);
ok(memcmp(buffer.data + 2, expect, 8) == 0 && wire_tell(&wire) == 10,
"wire_write_ralign()");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment