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 #ifndef GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ 20 #define GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ 21 22 #include <stdint.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 27 #include <grpc/grpc.h> 28 29 /** 30 * This method returns random bytes of certain length. 31 * 32 * - bytes: buffer to hold random bytes. 33 * - length: length of buffer to be populated. 34 */ 35 void gsec_test_random_bytes(uint8_t* bytes, size_t length); 36 37 /** 38 * This method returns an array of random bytes. 39 * 40 * - bytes: array to hold random bytes. 41 * - length: length of array to be populated. 42 */ 43 void gsec_test_random_array(uint8_t** bytes, size_t length); 44 45 /** 46 * This method returns a uint32 that's not quite uniformly random, but good 47 * enough for tests. 48 * 49 * - max_length: a max value the returned random number can choose. 50 */ 51 uint32_t gsec_test_bias_random_uint32(uint32_t max_length); 52 53 /** 54 * This method copies data from a source to a destination buffer. 55 * 56 * - src: a source buffer. 57 * - des: a destination buffer. 58 * - length: the length of source buffer to be copied from its beginning. 59 */ 60 void gsec_test_copy(const uint8_t* src, uint8_t** des, size_t length); 61 62 /** 63 * This method copies data from a source to a destination buffer, and flips one 64 * byte in the destination buffer randomly. 65 * 66 * - src: a source buffer. 67 * - des: a destination buffer. 68 * - length: the length of source buffer to be copied from its beginning. 69 */ 70 void gsec_test_copy_and_alter_random_byte(const uint8_t* src, uint8_t** des, 71 size_t source_len); 72 73 /** 74 * This method compares two grpc_status_code values, and verifies if one string 75 * is a substring of the other. 76 * 77 * - status1: the first grpc_status_code to be compared. 78 * - status2: the second grpc_status_code to be compared. 79 * - msg1: a string to be scanned. 80 * - msg2: a small string to be searched within msg1. 81 * 82 * If both checks succeed, the method returns 1 and otherwise, it returns 0. 83 */ 84 int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, 85 grpc_status_code status2, 86 const char* msg1, 87 const char* msg2); 88 89 #endif // GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ */ 90