chromium/third_party/grpc/src/src/core/tsi/fake_transport_security.cc

//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//

#include <grpc/support/port_platform.h>

#include "src/core/tsi/fake_transport_security.h"

#include <stdlib.h>
#include <string.h>

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>

#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/tsi/transport_security_grpc.h"

// --- Constants. ---
#define TSI_FAKE_FRAME_HEADER_SIZE
#define TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE
#define TSI_FAKE_DEFAULT_FRAME_SIZE
#define TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE

// --- Structure definitions. ---

// a frame is encoded like this:
// | size |     data    |
// where the size field value is the size of the size field plus the size of
// the data encoded in little endian on 4 bytes.
struct tsi_fake_frame {};
tsi_fake_handshake_message;

struct tsi_fake_handshaker {};
struct tsi_fake_frame_protector {};
struct tsi_fake_zero_copy_grpc_protector {};
// --- Utils. ---

static const char* tsi_fake_handshake_message_strings[] =;

static const char* tsi_fake_handshake_message_to_string(int msg) {}

static tsi_result tsi_fake_handshake_message_from_string(
    const char* msg_string, tsi_fake_handshake_message* msg,
    std::string* error) {}

static uint32_t load32_little_endian(const unsigned char* buf) {}

static void store32_little_endian(uint32_t value, unsigned char* buf) {}

static uint32_t read_frame_size(const grpc_slice_buffer* sb) {}

uint32_t tsi_fake_zero_copy_grpc_protector_next_frame_size(
    const grpc_slice_buffer* protected_slices) {}

static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) {}

// Checks if the frame's allocated size is at least frame->size, and reallocs
// more memory if necessary.
static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) {}

// Decodes the serialized fake frame contained in incoming_bytes, and fills
// frame with the contents of the decoded frame.
// This method should not be called if frame->needs_framing is not 0.
static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes,
                                        size_t* incoming_bytes_size,
                                        tsi_fake_frame* frame,
                                        std::string* error) {}

// Encodes a fake frame into its wire format and places the result in
// outgoing_bytes. outgoing_bytes_size indicates the size of the encoded frame.
// This method should not be called if frame->needs_framing is 0.
static tsi_result tsi_fake_frame_encode(unsigned char* outgoing_bytes,
                                        size_t* outgoing_bytes_size,
                                        tsi_fake_frame* frame,
                                        std::string* error) {}

// Sets the payload of a fake frame to contain the given data blob, where
// data_size indicates the size of data.
static void tsi_fake_frame_set_data(unsigned char* data, size_t data_size,
                                    tsi_fake_frame* frame) {}

// Destroys the contents of a fake frame.
static void tsi_fake_frame_destruct(tsi_fake_frame* frame) {}

// --- tsi_frame_protector methods implementation. ---

static tsi_result fake_protector_protect(tsi_frame_protector* self,
                                         const unsigned char* unprotected_bytes,
                                         size_t* unprotected_bytes_size,
                                         unsigned char* protected_output_frames,
                                         size_t* protected_output_frames_size) {}

static tsi_result fake_protector_protect_flush(
    tsi_frame_protector* self, unsigned char* protected_output_frames,
    size_t* protected_output_frames_size, size_t* still_pending_size) {}

static tsi_result fake_protector_unprotect(
    tsi_frame_protector* self, const unsigned char* protected_frames_bytes,
    size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes,
    size_t* unprotected_bytes_size) {}

static void fake_protector_destroy(tsi_frame_protector* self) {}

static const tsi_frame_protector_vtable frame_protector_vtable =;

// --- tsi_zero_copy_grpc_protector methods implementation. ---

static tsi_result fake_zero_copy_grpc_protector_protect(
    tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices,
    grpc_slice_buffer* protected_slices) {}

static tsi_result fake_zero_copy_grpc_protector_unprotect(
    tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices,
    grpc_slice_buffer* unprotected_slices, int* min_progress_size) {}

static void fake_zero_copy_grpc_protector_destroy(
    tsi_zero_copy_grpc_protector* self) {}

static tsi_result fake_zero_copy_grpc_protector_max_frame_size(
    tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) {}

static const tsi_zero_copy_grpc_protector_vtable
    zero_copy_grpc_protector_vtable =;

// --- tsi_handshaker_result methods implementation. ---

struct fake_handshaker_result {};

static tsi_result fake_handshaker_result_extract_peer(
    const tsi_handshaker_result* /*self*/, tsi_peer* peer) {}

static tsi_result fake_handshaker_result_get_frame_protector_type(
    const tsi_handshaker_result* /*self*/,
    tsi_frame_protector_type* frame_protector_type) {}

static tsi_result fake_handshaker_result_create_zero_copy_grpc_protector(
    const tsi_handshaker_result* /*self*/,
    size_t* max_output_protected_frame_size,
    tsi_zero_copy_grpc_protector** protector) {}

static tsi_result fake_handshaker_result_create_frame_protector(
    const tsi_handshaker_result* /*self*/,
    size_t* max_output_protected_frame_size, tsi_frame_protector** protector) {}

static tsi_result fake_handshaker_result_get_unused_bytes(
    const tsi_handshaker_result* self, const unsigned char** bytes,
    size_t* bytes_size) {}

static void fake_handshaker_result_destroy(tsi_handshaker_result* self) {}

static const tsi_handshaker_result_vtable handshaker_result_vtable =;

static tsi_result fake_handshaker_result_create(
    const unsigned char* unused_bytes, size_t unused_bytes_size,
    tsi_handshaker_result** handshaker_result, std::string* error) {}

// --- tsi_handshaker methods implementation. ---

static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
    tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size,
    std::string* error) {}

static tsi_result fake_handshaker_process_bytes_from_peer(
    tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size,
    std::string* error) {}

static tsi_result fake_handshaker_get_result(tsi_handshaker* self) {}

static void fake_handshaker_destroy(tsi_handshaker* self) {}

static tsi_result fake_handshaker_next(
    tsi_handshaker* self, const unsigned char* received_bytes,
    size_t received_bytes_size, const unsigned char** bytes_to_send,
    size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result,
    tsi_handshaker_on_next_done_cb /*cb*/, void* /*user_data*/,
    std::string* error) {}

static const tsi_handshaker_vtable handshaker_vtable =;

tsi_handshaker* tsi_create_fake_handshaker(int is_client) {}

tsi_frame_protector* tsi_create_fake_frame_protector(
    size_t* max_protected_frame_size) {}

tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector(
    size_t* max_protected_frame_size) {}