1 /* 2 * Copyright (c) 2024-2024 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 #include "extension.h" 16 #include "byte_buffer.h" 17 18 namespace OHOS { 19 namespace SignatureTools { 20 21 const int32_t Extension::EXTENSION_HEADER_SIZE = 8; 22 Extension()23Extension::Extension() 24 { 25 type = 0; 26 size = 0; 27 } 28 Extension(int32_t type, int32_t size)29Extension::Extension(int32_t type, int32_t size) 30 { 31 this->type = type; 32 this->size = size; 33 } 34 ~Extension()35Extension::~Extension() 36 { 37 } 38 GetSize()39int32_t Extension::GetSize() 40 { 41 return Extension::EXTENSION_HEADER_SIZE; 42 } 43 IsType(int32_t type)44bool Extension::IsType(int32_t type) 45 { 46 return this->type == type; 47 } 48 ToByteArray(std::vector<int8_t>& ret)49void Extension::ToByteArray(std::vector<int8_t>& ret) 50 { 51 std::unique_ptr<ByteBuffer> bf = std::make_unique<ByteBuffer> 52 (ByteBuffer(Extension::EXTENSION_HEADER_SIZE)); 53 bf->PutInt32(type); 54 bf->PutInt32(size); 55 bf->Flip(); 56 char dataArr[Extension::EXTENSION_HEADER_SIZE] = { 0 }; 57 bf->GetData(dataArr, Extension::EXTENSION_HEADER_SIZE); 58 ret = std::vector<int8_t>(dataArr, dataArr + Extension::EXTENSION_HEADER_SIZE); 59 } 60 61 } 62 }