asn1_compat.c
Go to the documentation of this file.
1 /* Copyright (c) 2016, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 
16 #include <openssl/bytestring.h>
17 
18 #include <assert.h>
19 #include <limits.h>
20 #include <string.h>
21 
22 #include <openssl/mem.h>
23 
24 #include "internal.h"
25 #include "../internal.h"
26 
27 
28 int CBB_finish_i2d(CBB *cbb, uint8_t **outp) {
29  assert(cbb->base->can_resize);
30 
31  uint8_t *der;
32  size_t der_len;
33  if (!CBB_finish(cbb, &der, &der_len)) {
34  CBB_cleanup(cbb);
35  return -1;
36  }
37  if (der_len > INT_MAX) {
38  OPENSSL_free(der);
39  return -1;
40  }
41  if (outp != NULL) {
42  if (*outp == NULL) {
43  *outp = der;
44  der = NULL;
45  } else {
46  OPENSSL_memcpy(*outp, der, der_len);
47  *outp += der_len;
48  }
49  }
50  OPENSSL_free(der);
51  return (int)der_len;
52 }
CBB_cleanup
#define CBB_cleanup
Definition: boringssl_prefix_symbols.h:1039
string.h
cbb_buffer_st::can_resize
char can_resize
Definition: bytestring.h:369
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
bytestring.h
internal.h
CBB_finish
#define CBB_finish
Definition: boringssl_prefix_symbols.h:1043
OPENSSL_memcpy
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:819
cbb_st::base
struct cbb_buffer_st * base
Definition: bytestring.h:376
CBB_finish_i2d
int CBB_finish_i2d(CBB *cbb, uint8_t **outp)
Definition: asn1_compat.c:28
mem.h
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
cbb_st
Definition: bytestring.h:375


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:44