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 "signed_file_pos.h" 16 17namespace OHOS { 18namespace SignatureTools { 19 20SignedFilePos::SignedFilePos(int32_t fileNameOffset, 21 int32_t fileNameSize, 22 int32_t signInfoOffset, 23 int32_t signInfoSize) 24 :fileNameOffset(fileNameOffset), 25 fileNameSize(fileNameSize), 26 signInfoOffset(signInfoOffset), 27 signInfoSize(signInfoSize) 28{ 29} 30 31int32_t SignedFilePos::GetFileNameOffset() 32{ 33 return fileNameOffset; 34} 35 36int32_t SignedFilePos::GetFileNameSize() 37{ 38 return fileNameSize; 39} 40 41int32_t SignedFilePos::GetSignInfoOffset() 42{ 43 return signInfoOffset; 44} 45 46int32_t SignedFilePos::GetSignInfoSize() 47{ 48 return signInfoSize; 49} 50 51void SignedFilePos::IncreaseFileNameOffset(int32_t incOffset) 52{ 53 fileNameOffset += incOffset; 54} 55 56void SignedFilePos::IncreaseSignInfoOffset(int32_t incOffset) 57{ 58 signInfoOffset += incOffset; 59} 60 61SignedFilePos SignedFilePos::FromByteArray(std::vector<int8_t> &bytes) 62{ 63 std::unique_ptr<ByteBuffer> bf = std::make_unique<ByteBuffer>(ByteBuffer(bytes.size())); 64 bf->PutData(0, bytes.data(), bytes.size()); 65 int32_t inFileNameOffset = 0; 66 bf->GetInt32(inFileNameOffset); 67 int32_t inFileNameSize = 0; 68 bf->GetInt32(inFileNameSize); 69 int32_t inSignInfoOffset = 0; 70 bf->GetInt32(inSignInfoOffset); 71 int32_t inSignInfoSize = 0; 72 bf->GetInt32(inSignInfoSize); 73 return SignedFilePos(inFileNameOffset, inFileNameSize, inSignInfoOffset, inSignInfoSize); 74} 75 76} 77}