1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_POSIX_SRC_SECURITYDATAHUKS_H 17 #define TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_POSIX_SRC_SECURITYDATAHUKS_H 18 #include "hks_client.h" 19 #include "hks_types.h" 20 #include <securec.h> 21 #include <stdbool.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 #include <string.h> 25 #include <hks_file_api.h> 26 #include "gtest/gtest.h" 27 #include <stdarg.h> 28 #include <sys/stat.h> 29 #include <unistd.h> 30 #include "hks_errno.h" 31 #include <sys/time.h> 32 #include <hks_hardware_api.h> 33 34 #define DOUBLE_INT(x) ((x) * 2) 35 #define DOUBLE_STR_LEN(x) ((x) * 2 + 1) 36 #define FILE_ERROR -1 37 #define HICHAIN_FILEPATH "/storage/" 38 #define HKS_FREE_PTR1(p) { if ((p) != NULL) { free(p); (p) = NULL; }} 39 40 constexpr int NUM1 = 1; 41 constexpr int NUM2 = 2; 42 constexpr int NUM3 = 3; 43 constexpr int NUM4 = 4; 44 constexpr int NUM5 = 5; 45 constexpr int NUM6 = 6; 46 constexpr int NUM8 = 8; 47 constexpr int NUM9 = 9; 48 constexpr int NUM10 = 10; 49 constexpr int NUM11 = 11; 50 constexpr int NUM12 = 12; 51 constexpr int NUM15 = 15; 52 constexpr int NUM16 = 16; 53 constexpr int NUM20 = 20; 54 constexpr int NUM30 = 30; 55 constexpr int NUM21 = 21; 56 constexpr int NUM24 = 24; 57 constexpr int NUM32 = 32; 58 constexpr int NUM60 = 60; 59 constexpr int NUM62 = 62; 60 constexpr int NUM64 = 64; 61 constexpr int NUM65 = 65; 62 constexpr int NUM88 = 88; 63 constexpr int NUM100 = 100; 64 constexpr int NUM128 = 128; 65 constexpr int NUM192 = 192; 66 constexpr int NUM256 = 256; 67 constexpr int NUM1025 = 1025; 68 constexpr unsigned NUM2048 = 2048; 69 constexpr int NUM1234567 = 1234567; 70 constexpr int NUM1000000 = 1000000; 71 constexpr int NUM134 = -134; 72 constexpr int NUM135 = -135; 73 constexpr int NUM142 = -142; 74 constexpr int NUM1000 = -1000; 75 constexpr int NUM1006 = -1006; 76 constexpr int NUM1007 = -1007; 77 constexpr int NUM1010 = -1010; 78 constexpr int G_COUNT_MEM = 10000; 79 constexpr int MAX_INT = 2147483647; 80 constexpr int FILE_PATH_LENGTH = 256; 81 82 using namespace std; 83 using namespace testing::ext; 84 using errno_t = int32_t; 85 86 errno_t FopenS(FILE **fp, const char *filename, const char *modes); 87 88 int32_t FileSize(const char *filename); 89 90 int32_t FileWrite(const char *filename, uint32_t offset, const uint8_t *buf, uint32_t len); 91 92 int32_t FileRead(const char *filename, uint32_t offset, uint8_t *buf, uint32_t len); 93 94 uint64_t GetTimeMs(); 95 96 void AddLog(const char* logType, const char *tag, const char *func, const char *format, const va_list* ap); 97 98 void Logi(const char *tag, const char *func, const char *format, ...); 99 100 void Logw(const char *tag, const char *func, const char *format, ...); 101 102 void Loge(const char *tag, const char *func, const char *format, ...); 103 104 void Logd(const char *tag, const char *func, const char *format, ...); 105 106 int32_t HksTestGetHardwareUdid(uint8_t* udid, uint32_t udidLen); 107 108 void HksStBlobInit1(struct hks_blob *blob, size_t nmemb, size_t size, uint8_t type); 109 110 void HksBlobDestroyT1(struct hks_blob *blob); 111 112 void HexStringToByte(const char *str, int nLen, unsigned char *pHex); 113 114 void BuildBlobData(struct hks_blob *param, const char *str, uint8_t type, uint32_t size, uint8_t isDataNull); 115 116 #endif 117