blob: d3bb04d07fc3a0b8562e72d8ac1329a84bc57b3f [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
Alexander Polcyndb3e8982018-02-21 16:59:24 -080022#include <grpc/support/port_platform.h>
23
Jiangtao Li0211cfb2017-08-07 11:24:07 -070024#include <grpc/slice_buffer.h>
25#include "src/core/tsi/transport_security.h"
26
Jiangtao Li0211cfb2017-08-07 11:24:07 -070027/* This method creates a tsi_zero_copy_grpc_protector object. It return TSI_OK
28 assuming there is no fatal error.
29 The caller is responsible for destroying the protector. */
30tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080031 const tsi_handshaker_result* self, size_t* max_output_protected_frame_size,
Craig Tillerbaa14a92017-11-03 09:09:36 -070032 tsi_zero_copy_grpc_protector** protector);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070033
34/* -- tsi_zero_copy_grpc_protector object -- */
35
36/* Outputs protected frames.
37 - unprotected_slices is the unprotected data to be protected.
38 - protected_slices is the protected output frames. One or more frames
39 may be produced in this protect function.
40 - This method returns TSI_OK in case of success or a specific error code in
41 case of failure. */
42tsi_result tsi_zero_copy_grpc_protector_protect(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080043 tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices,
44 grpc_slice_buffer* protected_slices);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070045
46/* Outputs unprotected bytes.
47 - protected_slices is the bytes of protected frames.
48 - unprotected_slices is the unprotected output data.
49 - This method returns TSI_OK in case of success. Success includes cases where
50 there is not enough data to output in which case unprotected_slices has 0
51 bytes. */
52tsi_result tsi_zero_copy_grpc_protector_unprotect(
Yash Tibrewal8cf14702017-12-06 09:47:54 -080053 tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices,
54 grpc_slice_buffer* unprotected_slices);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070055
56/* Destroys the tsi_zero_copy_grpc_protector object. */
Yash Tibrewal8cf14702017-12-06 09:47:54 -080057void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070058
59/* Base for tsi_zero_copy_grpc_protector implementations. */
60typedef struct {
Yash Tibrewal8cf14702017-12-06 09:47:54 -080061 tsi_result (*protect)(tsi_zero_copy_grpc_protector* self,
Craig Tillerbaa14a92017-11-03 09:09:36 -070062 grpc_slice_buffer* unprotected_slices,
63 grpc_slice_buffer* protected_slices);
Yash Tibrewal8cf14702017-12-06 09:47:54 -080064 tsi_result (*unprotect)(tsi_zero_copy_grpc_protector* self,
Craig Tillerbaa14a92017-11-03 09:09:36 -070065 grpc_slice_buffer* protected_slices,
66 grpc_slice_buffer* unprotected_slices);
Yash Tibrewal8cf14702017-12-06 09:47:54 -080067 void (*destroy)(tsi_zero_copy_grpc_protector* self);
Jiangtao Li0211cfb2017-08-07 11:24:07 -070068} tsi_zero_copy_grpc_protector_vtable;
69
70struct tsi_zero_copy_grpc_protector {
Craig Tillerbaa14a92017-11-03 09:09:36 -070071 const tsi_zero_copy_grpc_protector_vtable* vtable;
Jiangtao Li0211cfb2017-08-07 11:24:07 -070072};
73
Jiangtao Li0211cfb2017-08-07 11:24:07 -070074#endif /* GRPC_CORE_TSI_TRANSPORT_SECURITY_GRPC_H */