• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SEC_COMP_RAWDATA_H
17 #define SEC_COMP_RAWDATA_H
18 
19 #include "securec.h"
20 
21 namespace OHOS {
22 namespace Security {
23 namespace SecurityComponent {
24 constexpr int32_t MAX_RAW_DATA_SIZE = 4096;
25 class SecCompRawdata {
26 public:
27     uint32_t size = 0;
28     const void* data = nullptr;
29 
~SecCompRawdata()30     ~SecCompRawdata()
31     {
32         if (data != nullptr) {
33             delete[] static_cast<uint8_t*>(const_cast<void*>(data));
34         }
35     }
36 
RawDataCpy(const void * readData)37     int32_t RawDataCpy(const void* readData)
38     {
39         if ((size == 0) || (size >= MAX_RAW_DATA_SIZE)) {
40             return -1;
41         }
42         uint8_t* buffer = new (std::nothrow) uint8_t[size];
43         if (buffer == nullptr) {
44             return -1;
45         }
46         errno_t ret = memcpy_s(buffer, size, readData, size);
47         if (ret != EOK) {
48             delete[] buffer;
49             return -1;
50         }
51         data = reinterpret_cast<void *>(buffer);
52         return 0;
53     }
54 };
55 }  // namespace SecurityComponent
56 }  // namespace Security
57 }  // namespace OHOS
58 #endif // SEC_COMP_RAWDATA_H