/src/boringssl/crypto/asn1/a_dup.cc
Line | Count | Source |
1 | | // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <openssl/asn1.h> |
16 | | |
17 | | #include <openssl/err.h> |
18 | | #include <openssl/mem.h> |
19 | | |
20 | | // ASN1_ITEM version of dup: this follows the model above except we don't |
21 | | // need to allocate the buffer. At some point this could be rewritten to |
22 | | // directly dup the underlying structure instead of doing and encode and |
23 | | // decode. |
24 | 11.5k | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) { |
25 | 11.5k | unsigned char *b = nullptr; |
26 | 11.5k | const unsigned char *p; |
27 | 11.5k | long i; |
28 | 11.5k | void *ret; |
29 | | |
30 | 11.5k | if (x == nullptr) { |
31 | 0 | return nullptr; |
32 | 0 | } |
33 | | |
34 | 11.5k | i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it); |
35 | 11.5k | if (b == nullptr) { |
36 | 28 | return nullptr; |
37 | 28 | } |
38 | 11.4k | p = b; |
39 | 11.4k | ret = ASN1_item_d2i(nullptr, &p, i, it); |
40 | 11.4k | OPENSSL_free(b); |
41 | 11.4k | return ret; |
42 | 11.5k | } |