Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/bytestring/asn1_compat.c

raw
1 // Copyright (c) 2016, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4
5 #include <openssl/bytestring.h>
6
7 #include <assert.h>
8 #include <limits.h>
9 #include <string.h>
10
11 #include <openssl/mem.h>
12
13 #include "internal.h"
14 #include "../internal.h"
15
16
17 int CBB_finish_i2d(CBB *cbb, uint8_t **outp) {
18 assert(!cbb->is_child);
19 assert(cbb->u.base.can_resize);
20
21 uint8_t *der;
22 size_t der_len;
23 if (!CBB_finish(cbb, &der, &der_len)) {
24 CBB_cleanup(cbb);
25 return -1;
26 }
27 if (der_len > INT_MAX) {
28 OPENSSL_free(der);
29 return -1;
30 }
31 if (outp != NULL) {
32 if (*outp == NULL) {
33 *outp = der;
34 der = NULL;
35 } else {
36 OPENSSL_memcpy(*outp, der, der_len);
37 *outp += der_len;
38 }
39 }
40 OPENSSL_free(der);
41 return (int)der_len;
42 }