blob: 0156ff1c68adc9d726ecee409c987fe5c0c0d737 [file] [log] [blame]
Jiangtao Li0211cfb2017-08-07 11:24:07 -07001/*
2 *
3 * Copyright 2017 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
19#ifndef GRPC_CORE_TSI_TRANSPORT_SECURITY_GRPC_H
20#define GRPC_CORE_TSI_TRANSPORT_SECURITY_GRPC_H
21
22#include <grpc/slice_buffer.h>
23#include "src/core/tsi/transport_security.h"
24
Jiangtao Li0211cfb2017-08-07 11:24:07 -070025/* This method creates a tsi_zero_copy_grpc_protector object. It return TSI_OK
26 assuming there is no fatal error.
27 The caller is responsible for destroying the protector. */
28tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080029 const tsi_handshaker_result* self, size_t* max_output_protected_frame_size,
Craig Tillerbaa14a92017-11-03 09:09:36 -070030 tsi_zero_copy_grpc_protector** protector);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070031
32/* -- tsi_zero_copy_grpc_protector object -- */
33
34/* Outputs protected frames.
35 - unprotected_slices is the unprotected data to be protected.
36 - protected_slices is the protected output frames. One or more frames
37 may be produced in this protect function.
38 - This method returns TSI_OK in case of success or a specific error code in
39 case of failure. */
40tsi_result tsi_zero_copy_grpc_protector_protect(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080041 tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices,
42 grpc_slice_buffer* protected_slices);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070043
44/* Outputs unprotected bytes.
45 - protected_slices is the bytes of protected frames.
46 - unprotected_slices is the unprotected output data.
47 - This method returns TSI_OK in case of success. Success includes cases where
48 there is not enough data to output in which case unprotected_slices has 0
49 bytes. */
50tsi_result tsi_zero_copy_grpc_protector_unprotect(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080051 tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices,
52 grpc_slice_buffer* unprotected_slices);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070053
54/* Destroys the tsi_zero_copy_grpc_protector object. */
Yash Tibrewal8cf14702017-12-06 09:47:54 -080055void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070056
57/* Base for tsi_zero_copy_grpc_protector implementations. */
58typedef struct {
Yash Tibrewal8cf14702017-12-06 09:47:54 -080059 tsi_result (*protect)(tsi_zero_copy_grpc_protector* self,
Craig Tillerbaa14a92017-11-03 09:09:36 -070060 grpc_slice_buffer* unprotected_slices,
61 grpc_slice_buffer* protected_slices);
Yash Tibrewal8cf14702017-12-06 09:47:54 -080062 tsi_result (*unprotect)(tsi_zero_copy_grpc_protector* self,
Craig Tillerbaa14a92017-11-03 09:09:36 -070063 grpc_slice_buffer* protected_slices,
64 grpc_slice_buffer* unprotected_slices);
Yash Tibrewal8cf14702017-12-06 09:47:54 -080065 void (*destroy)(tsi_zero_copy_grpc_protector* self);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070066} tsi_zero_copy_grpc_protector_vtable;
67
68struct tsi_zero_copy_grpc_protector {
Craig Tillerbaa14a92017-11-03 09:09:36 -070069 const tsi_zero_copy_grpc_protector_vtable* vtable;
Jiangtao Li0211cfb2017-08-07 11:24:07 -070070};
71
Jiangtao Li0211cfb2017-08-07 11:24:07 -070072#endif /* GRPC_CORE_TSI_TRANSPORT_SECURITY_GRPC_H */