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