2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1.h>
16 void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
19 const unsigned char *p2;
27 b = OPENSSL_malloc(i + 10);
29 ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
35 ret = d2i(NULL, &p2, i);
43 * ASN1_ITEM version of dup: this follows the model above except we don't
44 * need to allocate the buffer. At some point this could be rewritten to
45 * directly dup the underlying structure instead of doing and encode and
49 void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
51 unsigned char *b = NULL;
52 const unsigned char *p;
59 i = ASN1_item_i2d(x, &b, it);
61 ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
65 ret = ASN1_item_d2i(NULL, &p, i, it);