]>
Commit | Line | Data |
---|---|---|
2039c421 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 3 | * |
365a2d99 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
2039c421 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
9d6b1ce6 | 12 | #include <openssl/asn1.h> |
d02b48c6 | 13 | |
f86c5c9a | 14 | #ifndef NO_OLD_ASN1 |
d02b48c6 | 15 | |
9fdcc21f | 16 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x) |
0f113f3e MC |
17 | { |
18 | unsigned char *b, *p; | |
19 | const unsigned char *p2; | |
20 | int i; | |
21 | char *ret; | |
d02b48c6 | 22 | |
0f113f3e | 23 | if (x == NULL) |
26a7d938 | 24 | return NULL; |
d02b48c6 | 25 | |
0f113f3e MC |
26 | i = i2d(x, NULL); |
27 | b = OPENSSL_malloc(i + 10); | |
28 | if (b == NULL) { | |
29 | ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE); | |
26a7d938 | 30 | return NULL; |
0f113f3e MC |
31 | } |
32 | p = b; | |
33 | i = i2d(x, &p); | |
34 | p2 = b; | |
35 | ret = d2i(NULL, &p2, i); | |
36 | OPENSSL_free(b); | |
26a7d938 | 37 | return ret; |
0f113f3e | 38 | } |
f86c5c9a DSH |
39 | |
40 | #endif | |
41 | ||
0f113f3e MC |
42 | /* |
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 | |
46 | * decode. | |
f86c5c9a DSH |
47 | */ |
48 | ||
9fdcc21f | 49 | void *ASN1_item_dup(const ASN1_ITEM *it, const void *x) |
0f113f3e MC |
50 | { |
51 | unsigned char *b = NULL; | |
52 | const unsigned char *p; | |
53 | long i; | |
54 | void *ret; | |
f86c5c9a | 55 | |
0f113f3e | 56 | if (x == NULL) |
26a7d938 | 57 | return NULL; |
f86c5c9a | 58 | |
0f113f3e MC |
59 | i = ASN1_item_i2d(x, &b, it); |
60 | if (b == NULL) { | |
61 | ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE); | |
26a7d938 | 62 | return NULL; |
0f113f3e MC |
63 | } |
64 | p = b; | |
65 | ret = ASN1_item_d2i(NULL, &p, i, it); | |
66 | OPENSSL_free(b); | |
26a7d938 | 67 | return ret; |
0f113f3e | 68 | } |