alts_crypter.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <string.h>
24 
25 #include <grpc/support/alloc.h>
26 
27 static void maybe_copy_error_msg(const char* src, char** dst) {
28  if (dst != nullptr && src != nullptr) {
29  *dst = static_cast<char*>(gpr_malloc(strlen(src) + 1));
30  memcpy(*dst, src, strlen(src) + 1);
31  }
32 }
33 
35  alts_crypter* crypter, unsigned char* data, size_t data_allocated_size,
36  size_t data_size, size_t* output_size, char** error_details) {
37  if (crypter != nullptr && crypter->vtable != nullptr &&
38  crypter->vtable->process_in_place != nullptr) {
39  return crypter->vtable->process_in_place(crypter, data, data_allocated_size,
40  data_size, output_size,
41  error_details);
42  }
43  /* An error occurred. */
44  const char error_msg[] =
45  "crypter or crypter->vtable has not been initialized properly.";
46  maybe_copy_error_msg(error_msg, error_details);
48 }
49 
51  if (crypter != nullptr && crypter->vtable != nullptr &&
52  crypter->vtable->num_overhead_bytes != nullptr) {
53  return crypter->vtable->num_overhead_bytes(crypter);
54  }
55  /* An error occurred. */
56  return 0;
57 }
58 
60  if (crypter != nullptr) {
61  if (crypter->vtable != nullptr && crypter->vtable->destruct != nullptr) {
62  crypter->vtable->destruct(crypter);
63  }
64  gpr_free(crypter);
65  }
66 }
dst
static const char dst[]
Definition: test-fs-copyfile.c:37
alts_crypter_process_in_place
grpc_status_code alts_crypter_process_in_place(alts_crypter *crypter, unsigned char *data, size_t data_allocated_size, size_t data_size, size_t *output_size, char **error_details)
Definition: alts_crypter.cc:34
string.h
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
alts_crypter.h
alts_crypter_num_overhead_bytes
size_t alts_crypter_num_overhead_bytes(const alts_crypter *crypter)
Definition: alts_crypter.cc:50
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Definition: include/grpc/impl/codegen/status.h:46
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
alts_crypter
Definition: alts_crypter.h:135
alts_crypter_vtable::num_overhead_bytes
size_t(* num_overhead_bytes)(const alts_crypter *crypter)
Definition: alts_crypter.h:125
alloc.h
alts_crypter::vtable
const alts_crypter_vtable * vtable
Definition: alts_crypter.h:136
alts_crypter_vtable::destruct
void(* destruct)(alts_crypter *crypter)
Definition: alts_crypter.h:131
alts_crypter_vtable::process_in_place
grpc_status_code(* process_in_place)(alts_crypter *crypter, unsigned char *data, size_t data_allocated_size, size_t data_size, size_t *output_size, char **error_details)
Definition: alts_crypter.h:126
maybe_copy_error_msg
static void maybe_copy_error_msg(const char *src, char **dst)
Definition: alts_crypter.cc:27
alts_crypter_destroy
void alts_crypter_destroy(alts_crypter *crypter)
Definition: alts_crypter.cc:59
port_platform.h


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