src/asn1_helper.c
author Krista Bennett <krista@pep-project.org>
Tue, 14 Aug 2018 13:45:34 +0200
branchENGINE-451
changeset 2826 07c080d73a63
parent 1513 e7f7e42385b5
permissions -rw-r--r--
ENGINE-451: abandoning branch - config files to be dealt with using gpgme (and hotfix will be external to engine
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@1116
     4
#include "asn1_helper.h"
vb@1116
     5
#include <assert.h>
vb@1116
     6
#include <stdlib.h>
vb@1116
     7
vb@1116
     8
growing_buf_t *new_growing_buf(void)
vb@1116
     9
{
vb@1116
    10
    growing_buf_t *result = calloc(1, sizeof(growing_buf_t));
vb@1116
    11
    assert(result);
vb@1116
    12
    return result;
vb@1116
    13
}
vb@1116
    14
vb@1116
    15
void free_growing_buf(growing_buf_t *buf)
vb@1116
    16
{
vb@1116
    17
    if (buf) {
vb@1116
    18
        free(buf->data);
vb@1116
    19
        free(buf);
vb@1116
    20
    }
vb@1116
    21
}
vb@1116
    22
vb@1116
    23
int consume_bytes(const void *src, size_t size, growing_buf_t *dst)
vb@1116
    24
{
vb@1116
    25
    assert(src && dst);
vb@1116
    26
    if (!(src && dst))
vb@1116
    27
        return -1;
vb@1116
    28
vb@1116
    29
    char *new_data = realloc(dst->data, dst->size + size + 1);
vb@1137
    30
    assert(new_data);
vb@1116
    31
    if (!new_data)
vb@1116
    32
        return -1;
vb@1116
    33
    dst->data = new_data;
vb@1116
    34
    memcpy(dst->data + dst->size, src, size);
vb@1116
    35
    dst->size += size;
vb@1116
    36
    dst->data[dst->size] = 0; // safeguard
vb@1116
    37
vb@1116
    38
    return 1;
vb@1116
    39
}
vb@1116
    40