1 /* 2 * Copyright (c) 2025 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 ACCESSIBILITY_SEC_COMP_RAWDATA_H 17 #define ACCESSIBILITY_SEC_COMP_RAWDATA_H 18 19 #include "securec.h" 20 21 namespace OHOS { 22 namespace Accessibility { 23 constexpr int32_t MAX_RAW_DATA_SIZE = 4096; 24 class AccessibilitySecCompRawdata { 25 public: 26 uint32_t size = 0; 27 uint8_t* data = nullptr; 28 ~AccessibilitySecCompRawdata()29 ~AccessibilitySecCompRawdata() 30 { 31 if (isCopy_ && data != nullptr) { 32 delete[] data; 33 } 34 } 35 RawDataCpy(const void * readData)36 int32_t RawDataCpy(const void* readData) 37 { 38 if ((size == 0) || (size >= MAX_RAW_DATA_SIZE)) { 39 return -1; 40 } 41 uint8_t* buffer = new (std::nothrow) uint8_t[size]; 42 if (buffer == nullptr) { 43 return -1; 44 } 45 errno_t ret = memcpy_s(buffer, size, readData, size); 46 if (ret != EOK) { 47 delete[] buffer; 48 return -1; 49 } 50 data = buffer; 51 isCopy_ = true; 52 return 0; 53 } 54 private: 55 bool isCopy_ = false; 56 }; 57 } // namespace Accessibility 58 } // namespace OHOS 59 #endif // ACCESSIBILITY_SEC_COMP_RAWDATA_H