1
#pragma once
2

            
3
#include "envoy/buffer/buffer.h"
4

            
5
#include "source/extensions/transport_sockets/alts/grpc_tsi.h"
6

            
7
#include "grpc/slice_buffer.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace TransportSockets {
12
namespace Alts {
13

            
14
/**
15
 * A C++ wrapper for tsi_frame_protector interface.
16
 * For detail of tsi_frame_protector, see
17
 * https://github.com/grpc/grpc/blob/v1.10.0/src/core/tsi/transport_security_interface.h#L70
18
 */
19
class TsiFrameProtector final {
20
public:
21
  explicit TsiFrameProtector(CFrameProtectorPtr&& frame_protector);
22

            
23
  /**
24
   * Wrapper for tsi_frame_protector_protect
25
   * @param input_slice supplies the input data to protect. Its ownership will
26
   * be transferred.
27
   * @param output supplies the buffer where the protected data will be stored.
28
   * @return tsi_result the status.
29
   */
30
  tsi_result protect(const grpc_slice& input_slice, Buffer::Instance& output);
31

            
32
  /**
33
   * Wrapper for tsi_frame_protector_unprotect
34
   * @param input supplies the input data to unprotect, the method will drain it when it is
35
   * processed.
36
   * @param output supplies the buffer where the unprotected data will be stored.
37
   * @return tsi_result the status.
38
   */
39
  tsi_result unprotect(Buffer::Instance& input, Buffer::Instance& output);
40

            
41
private:
42
  CFrameProtectorPtr frame_protector_;
43
};
44

            
45
using TsiFrameProtectorPtr = std::unique_ptr<TsiFrameProtector>;
46

            
47
} // namespace Alts
48
} // namespace TransportSockets
49
} // namespace Extensions
50
} // namespace Envoy