• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9 
10 #include <openssl/asn1.h>
11 
12 #include <openssl/err.h>
13 #include <openssl/mem.h>
14 
15 // ASN1_ITEM version of dup: this follows the model above except we don't
16 // need to allocate the buffer. At some point this could be rewritten to
17 // directly dup the underlying structure instead of doing and encode and
18 // decode.
ASN1_item_dup(const ASN1_ITEM * it,void * x)19 void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
20   unsigned char *b = NULL;
21   const unsigned char *p;
22   long i;
23   void *ret;
24 
25   if (x == NULL) {
26     return NULL;
27   }
28 
29   i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
30   if (b == NULL) {
31     return NULL;
32   }
33   p = b;
34   ret = ASN1_item_d2i(NULL, &p, i, it);
35   OPENSSL_free(b);
36   return ret;
37 }
38