mirror of https://github.com/grpc/grpc.git
commit
febfd32af9
22 changed files with 809 additions and 0 deletions
@ -0,0 +1,232 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/transport/chttp2/transport/bin_decoder.h" |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include "src/core/lib/support/string.h" |
||||
|
||||
static uint8_t decode_table[] = { |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 62, 0x40, 0x40, 0x40, 63, |
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0, 1, 2, 3, 4, 5, 6, |
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
||||
19, 20, 21, 22, 23, 24, 25, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
||||
49, 50, 51, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||
0x40, 0x40, 0x40, 0x40}; |
||||
|
||||
static const uint8_t tail_xtra[4] = {0, 0, 1, 2}; |
||||
|
||||
static bool input_is_valid(uint8_t *input_ptr, size_t length) { |
||||
size_t i; |
||||
|
||||
for (i = 0; i < length; ++i) { |
||||
if ((decode_table[input_ptr[i]] & 0xC0) != 0) { |
||||
gpr_log(GPR_ERROR, |
||||
"Base64 decoding failed, invalid character '%c' in base64 " |
||||
"input.\n", |
||||
(char)(*input_ptr)); |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
#define COMPOSE_OUTPUT_BYTE_0(input_ptr) \ |
||||
(uint8_t)((decode_table[input_ptr[0]] << 2) | \
|
||||
(decode_table[input_ptr[1]] >> 4)) |
||||
|
||||
#define COMPOSE_OUTPUT_BYTE_1(input_ptr) \ |
||||
(uint8_t)((decode_table[input_ptr[1]] << 4) | \
|
||||
(decode_table[input_ptr[2]] >> 2)) |
||||
|
||||
#define COMPOSE_OUTPUT_BYTE_2(input_ptr) \ |
||||
(uint8_t)((decode_table[input_ptr[2]] << 6) | decode_table[input_ptr[3]]) |
||||
|
||||
bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx) { |
||||
size_t input_tail; |
||||
|
||||
if (ctx->input_cur > ctx->input_end || ctx->output_cur > ctx->output_end) { |
||||
return false; |
||||
} |
||||
|
||||
// Process a block of 4 input characters and 3 output bytes
|
||||
while (ctx->input_end >= ctx->input_cur + 4 && |
||||
ctx->output_end >= ctx->output_cur + 3) { |
||||
if (!input_is_valid(ctx->input_cur, 4)) return false; |
||||
ctx->output_cur[0] = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||
ctx->output_cur[1] = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||
ctx->output_cur[2] = COMPOSE_OUTPUT_BYTE_2(ctx->input_cur); |
||||
ctx->output_cur += 3; |
||||
ctx->input_cur += 4; |
||||
} |
||||
|
||||
// Process the tail of input data
|
||||
input_tail = (size_t)(ctx->input_end - ctx->input_cur); |
||||
if (input_tail == 4) { |
||||
// Process the input data with pad chars
|
||||
if (ctx->input_cur[3] == '=') { |
||||
if (ctx->input_cur[2] == '=' && ctx->output_end >= ctx->output_cur + 1) { |
||||
if (!input_is_valid(ctx->input_cur, 2)) return false; |
||||
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||
ctx->input_cur += 4; |
||||
} else if (ctx->output_end >= ctx->output_cur + 2) { |
||||
if (!input_is_valid(ctx->input_cur, 3)) return false; |
||||
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||
; |
||||
ctx->input_cur += 4; |
||||
} |
||||
} |
||||
|
||||
} else if (ctx->contains_tail && input_tail > 1) { |
||||
// Process the input data without pad chars, but constains_tail is set
|
||||
if (ctx->output_end >= ctx->output_cur + tail_xtra[input_tail]) { |
||||
if (!input_is_valid(ctx->input_cur, input_tail)) return false; |
||||
switch (input_tail) { |
||||
case 3: |
||||
ctx->output_cur[1] = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||
case 2: |
||||
ctx->output_cur[0] = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||
} |
||||
ctx->output_cur += tail_xtra[input_tail]; |
||||
ctx->input_cur += input_tail; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
gpr_slice grpc_chttp2_base64_decode(gpr_slice input) { |
||||
size_t input_length = GPR_SLICE_LENGTH(input); |
||||
size_t output_length = input_length / 4 * 3; |
||||
struct grpc_base64_decode_context ctx; |
||||
gpr_slice output; |
||||
|
||||
if (input_length % 4 != 0) { |
||||
gpr_log(GPR_ERROR, |
||||
"Base64 decoding failed, input of " |
||||
"grpc_chttp2_base64_decode has a length of %d, which is not a " |
||||
"multiple of 4.\n", |
||||
(int)input_length); |
||||
return gpr_empty_slice(); |
||||
} |
||||
|
||||
if (input_length > 0) { |
||||
uint8_t *input_end = GPR_SLICE_END_PTR(input); |
||||
if (*(--input_end) == '=') { |
||||
output_length--; |
||||
if (*(--input_end) == '=') { |
||||
output_length--; |
||||
} |
||||
} |
||||
} |
||||
output = gpr_slice_malloc(output_length); |
||||
|
||||
ctx.input_cur = GPR_SLICE_START_PTR(input); |
||||
ctx.input_end = GPR_SLICE_END_PTR(input); |
||||
ctx.output_cur = GPR_SLICE_START_PTR(output); |
||||
ctx.output_end = GPR_SLICE_END_PTR(output); |
||||
ctx.contains_tail = false; |
||||
|
||||
if (!grpc_base64_decode_partial(&ctx)) { |
||||
char *s = gpr_dump_slice(input, GPR_DUMP_ASCII); |
||||
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); |
||||
gpr_free(s); |
||||
gpr_slice_unref(output); |
||||
return gpr_empty_slice(); |
||||
} |
||||
GPR_ASSERT(ctx.output_cur == GPR_SLICE_END_PTR(output)); |
||||
GPR_ASSERT(ctx.input_cur == GPR_SLICE_END_PTR(input)); |
||||
return output; |
||||
} |
||||
|
||||
gpr_slice grpc_chttp2_base64_decode_with_length(gpr_slice input, |
||||
size_t output_length) { |
||||
size_t input_length = GPR_SLICE_LENGTH(input); |
||||
gpr_slice output = gpr_slice_malloc(output_length); |
||||
struct grpc_base64_decode_context ctx; |
||||
|
||||
// The length of a base64 string cannot be 4 * n + 1
|
||||
if (input_length % 4 == 1) { |
||||
gpr_log(GPR_ERROR, |
||||
"Base64 decoding failed, input of " |
||||
"grpc_chttp2_base64_decode_with_length has a length of %d, which " |
||||
"has a tail of 1 byte.\n", |
||||
(int)input_length); |
||||
gpr_slice_unref(output); |
||||
return gpr_empty_slice(); |
||||
} |
||||
|
||||
if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { |
||||
gpr_log(GPR_ERROR, |
||||
"Base64 decoding failed, output_length %d is longer " |
||||
"than the max possible output length %d.\n", |
||||
(int)output_length, |
||||
(int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); |
||||
gpr_slice_unref(output); |
||||
return gpr_empty_slice(); |
||||
} |
||||
|
||||
ctx.input_cur = GPR_SLICE_START_PTR(input); |
||||
ctx.input_end = GPR_SLICE_END_PTR(input); |
||||
ctx.output_cur = GPR_SLICE_START_PTR(output); |
||||
ctx.output_end = GPR_SLICE_END_PTR(output); |
||||
ctx.contains_tail = true; |
||||
|
||||
if (!grpc_base64_decode_partial(&ctx)) { |
||||
char *s = gpr_dump_slice(input, GPR_DUMP_ASCII); |
||||
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); |
||||
gpr_free(s); |
||||
gpr_slice_unref(output); |
||||
return gpr_empty_slice(); |
||||
} |
||||
GPR_ASSERT(ctx.output_cur == GPR_SLICE_END_PTR(output)); |
||||
GPR_ASSERT(ctx.input_cur <= GPR_SLICE_END_PTR(input)); |
||||
return output; |
||||
} |
@ -0,0 +1,66 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H |
||||
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H |
||||
|
||||
#include <grpc/support/slice.h> |
||||
#include <stdbool.h> |
||||
|
||||
struct grpc_base64_decode_context { |
||||
/* input/output: */ |
||||
uint8_t *input_cur; |
||||
uint8_t *input_end; |
||||
uint8_t *output_cur; |
||||
uint8_t *output_end; |
||||
/* Indicate if the decoder should handle the tail of input data*/ |
||||
bool contains_tail; |
||||
}; |
||||
|
||||
/* base64 decode a grpc_base64_decode_context util either input_end is reached
|
||||
or output_end is reached. When input_end is reached, (input_end - input_cur) |
||||
is less than 4. When output_end is reached, (output_end - output_cur) is less |
||||
than 3. Returns false if decoding is failed. */ |
||||
bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx); |
||||
|
||||
/* base64 decode a slice with pad chars. Returns a new slice, does not take
|
||||
ownership of the input. Returns an empty slice if decoding is failed. */ |
||||
gpr_slice grpc_chttp2_base64_decode(gpr_slice input); |
||||
|
||||
/* base64 decode a slice without pad chars, data length is needed. Returns a new
|
||||
slice, does not take ownership of the input. Returns an empty slice if |
||||
decoding is failed. */ |
||||
gpr_slice grpc_chttp2_base64_decode_with_length(gpr_slice input, |
||||
size_t output_length); |
||||
|
||||
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */ |
@ -0,0 +1,144 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/transport/chttp2/transport/bin_decoder.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include "src/core/ext/transport/chttp2/transport/bin_encoder.h" |
||||
#include "src/core/lib/support/string.h" |
||||
|
||||
static int all_ok = 1; |
||||
|
||||
static void expect_slice_eq(gpr_slice expected, gpr_slice slice, char *debug, |
||||
int line) { |
||||
if (0 != gpr_slice_cmp(slice, expected)) { |
||||
char *hs = gpr_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); |
||||
char *he = gpr_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); |
||||
gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, |
||||
he); |
||||
gpr_free(hs); |
||||
gpr_free(he); |
||||
all_ok = 0; |
||||
} |
||||
gpr_slice_unref(expected); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
static gpr_slice base64_encode(const char *s) { |
||||
gpr_slice ss = gpr_slice_from_copied_string(s); |
||||
gpr_slice out = grpc_chttp2_base64_encode(ss); |
||||
gpr_slice_unref(ss); |
||||
return out; |
||||
} |
||||
|
||||
static gpr_slice base64_decode(const char *s) { |
||||
gpr_slice ss = gpr_slice_from_copied_string(s); |
||||
gpr_slice out = grpc_chttp2_base64_decode(ss); |
||||
gpr_slice_unref(ss); |
||||
return out; |
||||
} |
||||
|
||||
static gpr_slice base64_decode_with_length(const char *s, |
||||
size_t output_length) { |
||||
gpr_slice ss = gpr_slice_from_copied_string(s); |
||||
gpr_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); |
||||
gpr_slice_unref(ss); |
||||
return out; |
||||
} |
||||
|
||||
#define EXPECT_SLICE_EQ(expected, slice) \ |
||||
expect_slice_eq( \
|
||||
gpr_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \
|
||||
#slice, __LINE__); |
||||
|
||||
#define ENCODE_AND_DECODE(s) \ |
||||
EXPECT_SLICE_EQ( \
|
||||
s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); |
||||
|
||||
int main(int argc, char **argv) { |
||||
/* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which
|
||||
takes encoded base64 strings without pad chars, but output length is |
||||
required. */ |
||||
/* Base64 test vectors from RFC 4648 */ |
||||
ENCODE_AND_DECODE(""); |
||||
ENCODE_AND_DECODE("f"); |
||||
ENCODE_AND_DECODE("foo"); |
||||
ENCODE_AND_DECODE("fo"); |
||||
ENCODE_AND_DECODE("foob"); |
||||
ENCODE_AND_DECODE("fooba"); |
||||
ENCODE_AND_DECODE("foobar"); |
||||
|
||||
ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); |
||||
|
||||
/* Base64 test vectors from RFC 4648, with pad chars */ |
||||
/* BASE64("") = "" */ |
||||
EXPECT_SLICE_EQ("", base64_decode("")); |
||||
/* BASE64("f") = "Zg==" */ |
||||
EXPECT_SLICE_EQ("f", base64_decode("Zg==")); |
||||
/* BASE64("fo") = "Zm8=" */ |
||||
EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); |
||||
/* BASE64("foo") = "Zm9v" */ |
||||
EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); |
||||
/* BASE64("foob") = "Zm9vYg==" */ |
||||
EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); |
||||
/* BASE64("fooba") = "Zm9vYmE=" */ |
||||
EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); |
||||
/* BASE64("foobar") = "Zm9vYmFy" */ |
||||
EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); |
||||
|
||||
EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); |
||||
|
||||
// Test illegal input length in grpc_chttp2_base64_decode
|
||||
EXPECT_SLICE_EQ("", base64_decode("a")); |
||||
EXPECT_SLICE_EQ("", base64_decode("ab")); |
||||
EXPECT_SLICE_EQ("", base64_decode("abc")); |
||||
|
||||
// Test illegal charactors in grpc_chttp2_base64_decode
|
||||
EXPECT_SLICE_EQ("", base64_decode("Zm:v")); |
||||
EXPECT_SLICE_EQ("", base64_decode("Zm=v")); |
||||
|
||||
// Test output_length longer than max possible output length in
|
||||
// grpc_chttp2_base64_decode_with_length
|
||||
EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); |
||||
EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); |
||||
EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); |
||||
|
||||
// Test illegal charactors in grpc_chttp2_base64_decode_with_length
|
||||
EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); |
||||
EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); |
||||
|
||||
return all_ok ? 0 : 1; |
||||
} |
@ -0,0 +1,193 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props" Condition="Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\1.0.204.1.props')" /> |
||||
<ItemGroup Label="ProjectConfigurations"> |
||||
<ProjectConfiguration Include="Debug|Win32"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Debug|x64"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|Win32"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|x64"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
</ItemGroup> |
||||
<PropertyGroup Label="Globals"> |
||||
<ProjectGuid>{6BFAC6BA-3B9D-E8F5-BE35-91E8EFB9E25B}</ProjectGuid> |
||||
<IgnoreWarnIntDirInTempDetected>true</IgnoreWarnIntDirInTempDetected> |
||||
<IntDir>$(SolutionDir)IntDir\$(MSBuildProjectName)\</IntDir> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0'" Label="Configuration"> |
||||
<PlatformToolset>v100</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '11.0'" Label="Configuration"> |
||||
<PlatformToolset>v110</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '12.0'" Label="Configuration"> |
||||
<PlatformToolset>v120</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'" Label="Configuration"> |
||||
<PlatformToolset>v140</PlatformToolset> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
<ImportGroup Label="ExtensionSettings"> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\global.props" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\openssl.props" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\winsock.props" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\zlib.props" /> |
||||
</ImportGroup> |
||||
<PropertyGroup Label="UserMacros" /> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> |
||||
<TargetName>bin_decoder_test</TargetName> |
||||
<Linkage-grpc_dependencies_zlib>static</Linkage-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_zlib>Debug</Configuration-grpc_dependencies_zlib> |
||||
<Linkage-grpc_dependencies_openssl>static</Linkage-grpc_dependencies_openssl> |
||||
<Configuration-grpc_dependencies_openssl>Debug</Configuration-grpc_dependencies_openssl> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> |
||||
<TargetName>bin_decoder_test</TargetName> |
||||
<Linkage-grpc_dependencies_zlib>static</Linkage-grpc_dependencies_zlib> |
||||
<Configuration-grpc_dependencies_zlib>Release</Configuration-grpc_dependencies_zlib> |
||||
<Linkage-grpc_dependencies_openssl>static</Linkage-grpc_dependencies_openssl> |
||||
<Configuration-grpc_dependencies_openssl>Release</Configuration-grpc_dependencies_openssl> |
||||
</PropertyGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>Disabled</Optimization> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
<MinimalRebuild Condition="$(Jenkins)">false</MinimalRebuild> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>Disabled</Optimization> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
<MinimalRebuild Condition="$(Jenkins)">false</MinimalRebuild> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>MaxSpeed</Optimization> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
<MinimalRebuild Condition="$(Jenkins)">false</MinimalRebuild> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
<ClCompile> |
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<Optimization>MaxSpeed</Optimization> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> |
||||
<TreatWarningAsError>true</TreatWarningAsError> |
||||
<DebugInformationFormat Condition="$(Jenkins)">None</DebugInformationFormat> |
||||
<MinimalRebuild Condition="$(Jenkins)">false</MinimalRebuild> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation Condition="!$(Jenkins)">true</GenerateDebugInformation> |
||||
<GenerateDebugInformation Condition="$(Jenkins)">false</GenerateDebugInformation> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
|
||||
<ItemGroup> |
||||
<ClCompile Include="$(SolutionDir)\..\test\core\transport\chttp2\bin_decoder_test.c"> |
||||
</ClCompile> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\grpc_test_util\grpc_test_util.vcxproj"> |
||||
<Project>{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}</Project> |
||||
</ProjectReference> |
||||
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\grpc\grpc.vcxproj"> |
||||
<Project>{29D16885-7228-4C31-81ED-5F9187C7F2A9}</Project> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="packages.config" /> |
||||
</ItemGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
<ImportGroup Label="ExtensionTargets"> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets" Condition="Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies\grpc.dependencies.zlib.targets')" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets" Condition="Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies\grpc.dependencies.zlib.targets')" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets" Condition="Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies\grpc.dependencies.openssl.targets')" /> |
||||
<Import Project="$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets" Condition="Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies\grpc.dependencies.openssl.targets')" /> |
||||
</ImportGroup> |
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
||||
<PropertyGroup> |
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> |
||||
</PropertyGroup> |
||||
<Error Condition="!Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.redist.1.2.8.10\build\native\grpc.dependencies.zlib.redist.targets')" /> |
||||
<Error Condition="!Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.zlib.1.2.8.10\build\native\grpc.dependencies.zlib.targets')" /> |
||||
<Error Condition="!Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.redist.1.0.204.1\build\native\grpc.dependencies.openssl.redist.targets')" /> |
||||
<Error Condition="!Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.props')" /> |
||||
<Error Condition="!Exists('$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\..\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\grpc.dependencies.openssl.targets')" /> |
||||
</Target> |
||||
</Project> |
||||
|
@ -0,0 +1,24 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
||||
<ClCompile Include="$(SolutionDir)\..\test\core\transport\chttp2\bin_decoder_test.c"> |
||||
<Filter>test\core\transport\chttp2</Filter> |
||||
</ClCompile> |
||||
</ItemGroup> |
||||
|
||||
<ItemGroup> |
||||
<Filter Include="test"> |
||||
<UniqueIdentifier>{6865d212-f7ee-5eb1-aa2e-c8ce3dd9f834}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core"> |
||||
<UniqueIdentifier>{79be26a4-2e58-2868-d847-e692e13ed37a}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core\transport"> |
||||
<UniqueIdentifier>{2b861a75-ca04-d422-f519-5b6d3c81e6e4}</UniqueIdentifier> |
||||
</Filter> |
||||
<Filter Include="test\core\transport\chttp2"> |
||||
<UniqueIdentifier>{9725ed79-ddf1-6ffe-21e1-14fef9d481a6}</UniqueIdentifier> |
||||
</Filter> |
||||
</ItemGroup> |
||||
</Project> |
||||
|
Loading…
Reference in new issue