src/asn1_helper.c
author Krista Bennett <krista@pep-project.org>
Wed, 15 Mar 2017 18:02:46 +0100
changeset 1674 5639f969866a
parent 1513 e7f7e42385b5
permissions -rw-r--r--
Added pgp_encrypt_only stubs for NetPGP
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include "asn1_helper.h"
     5 #include <assert.h>
     6 #include <stdlib.h>
     7 
     8 growing_buf_t *new_growing_buf(void)
     9 {
    10     growing_buf_t *result = calloc(1, sizeof(growing_buf_t));
    11     assert(result);
    12     return result;
    13 }
    14 
    15 void free_growing_buf(growing_buf_t *buf)
    16 {
    17     if (buf) {
    18         free(buf->data);
    19         free(buf);
    20     }
    21 }
    22 
    23 int consume_bytes(const void *src, size_t size, growing_buf_t *dst)
    24 {
    25     assert(src && dst);
    26     if (!(src && dst))
    27         return -1;
    28 
    29     char *new_data = realloc(dst->data, dst->size + size + 1);
    30     assert(new_data);
    31     if (!new_data)
    32         return -1;
    33     dst->data = new_data;
    34     memcpy(dst->data + dst->size, src, size);
    35     dst->size += size;
    36     dst->data[dst->size] = 0; // safeguard
    37 
    38     return 1;
    39 }
    40