grpc
test
core
tsi
alts
crypt
gsec_test_util.cc
Go to the documentation of this file.
1
/*
2
*
3
* Copyright 2018 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
#include "
test/core/tsi/alts/crypt/gsec_test_util.h
"
20
21
#include <time.h>
22
23
#include <
grpc/support/alloc.h
>
24
25
void
gsec_test_random_bytes
(
uint8_t
*
bytes
,
size_t
length
) {
26
srand(time(
nullptr
));
27
size_t
ind
;
28
for
(
ind
= 0;
ind
<
length
;
ind
++) {
29
bytes
[
ind
] =
static_cast<
uint8_t
>
(rand() % 255 + 1);
30
}
31
}
32
33
void
gsec_test_random_array
(
uint8_t
**
bytes
,
size_t
length
) {
34
if
(
bytes
!=
nullptr
) {
35
*
bytes
=
static_cast<
uint8_t
*
>
(
gpr_malloc
(
length
));
36
gsec_test_random_bytes
(*
bytes
,
length
);
37
}
else
{
38
fprintf(
stderr
,
"bytes buffer is nullptr in gsec_test_random_array()."
);
39
abort();
40
}
41
}
42
43
uint32_t
gsec_test_bias_random_uint32
(
uint32_t
max_length) {
44
uint32_t
value
;
45
gsec_test_random_bytes
(
reinterpret_cast<
uint8_t
*
>
(&
value
),
sizeof
(
value
));
46
return
value
% max_length;
47
}
48
49
void
gsec_test_copy
(
const
uint8_t
* src,
uint8_t
** des,
size_t
source_len) {
50
if
(src !=
nullptr
&& des !=
nullptr
) {
51
*des =
static_cast<
uint8_t
*
>
(
gpr_malloc
(source_len));
52
if
(*des !=
nullptr
) {
53
memcpy
(*des, src, source_len);
54
}
55
}
else
{
56
fprintf(
stderr
,
"Either src or des buffer is nullptr in gsec_test_copy()."
);
57
abort();
58
}
59
}
60
61
void
gsec_test_copy_and_alter_random_byte
(
const
uint8_t
* src,
uint8_t
** des,
62
size_t
source_len) {
63
if
(src !=
nullptr
&& des !=
nullptr
) {
64
*des =
static_cast<
uint8_t
*
>
(
gpr_malloc
(source_len));
65
memcpy
(*des, src, source_len);
66
uint32_t
offset
;
67
offset
=
gsec_test_bias_random_uint32
(
static_cast<
uint32_t
>
(source_len));
68
(*(*des +
offset
))++;
69
}
else
{
70
fprintf(
stderr
,
71
"Either src or des is nullptr in "
72
"gsec_test_copy_and_alter_random_byte()."
);
73
abort();
74
}
75
}
76
77
int
gsec_test_expect_compare_code_and_substr
(
grpc_status_code
status1,
78
grpc_status_code
status2,
79
const
char
* msg1,
80
const
char
* msg2) {
81
int
failure = 1;
82
if
(status1 != status2) {
83
fprintf(
stderr
,
"Status %d does not equal %d.\n"
, status1, status2);
84
failure = 0;
85
}
86
if
(strstr(msg1, msg2) ==
nullptr
) {
87
fprintf(
stderr
,
"Status message <%s> does not contain <%s>.\n"
, msg1, msg2);
88
failure = 0;
89
}
90
return
failure;
91
}
gsec_test_bias_random_uint32
uint32_t gsec_test_bias_random_uint32(uint32_t max_length)
Definition:
gsec_test_util.cc:43
ind
Definition:
bloaty/third_party/zlib/examples/gun.c:81
grpc_status_code
grpc_status_code
Definition:
include/grpc/impl/codegen/status.h:28
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition:
alloc.cc:29
gsec_test_random_array
void gsec_test_random_array(uint8_t **bytes, size_t length)
Definition:
gsec_test_util.cc:33
gsec_test_copy
void gsec_test_copy(const uint8_t *src, uint8_t **des, size_t source_len)
Definition:
gsec_test_util.cc:49
uint8_t
unsigned char uint8_t
Definition:
stdint-msvc2008.h:78
python_utils.port_server.stderr
stderr
Definition:
port_server.py:51
uint32_t
unsigned int uint32_t
Definition:
stdint-msvc2008.h:80
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
gsec_test_util.h
value
const char * value
Definition:
hpack_parser_table.cc:165
bytes
uint8 bytes[10]
Definition:
bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
alloc.h
gsec_test_expect_compare_code_and_substr
int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, grpc_status_code status2, const char *msg1, const char *msg2)
Definition:
gsec_test_util.cc:77
gsec_test_random_bytes
void gsec_test_random_bytes(uint8_t *bytes, size_t length)
Definition:
gsec_test_util.cc:25
gsec_test_copy_and_alter_random_byte
void gsec_test_copy_and_alter_random_byte(const uint8_t *src, uint8_t **des, size_t source_len)
Definition:
gsec_test_util.cc:61
length
std::size_t length
Definition:
abseil-cpp/absl/time/internal/test_util.cc:57
offset
voidpf uLong offset
Definition:
bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:45