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 16 #include <memory> 17 #include <fstream> 18 #include <gtest/gtest.h> 19 20 #include "elf_sign_block.h" 21 #include "byte_buffer.h" 22 23 namespace OHOS { 24 namespace SignatureTools { 25 26 class ElfSignBlockTest : public testing::Test { 27 public: SetUpTestCase(void)28 static void SetUpTestCase(void) {}; TearDownTestCase()29 static void TearDownTestCase() {}; SetUp()30 void SetUp() {}; TearDown()31 void TearDown() {}; 32 }; 33 34 /** 35 * @tc.name: FromByteArray001 36 * @tc.desc: The return will be false,because the data has wrong signature length in the ElfSignBlock. 37 * @tc.size: MEDIUM 38 * @tc.type: FUNC 39 * @tc.level Level 1 40 * @tc.require: SR000H63TL 41 */ 42 HWTEST_F(ElfSignBlockTest, FromByteArray001, testing::ext::TestSize.Level1) 43 { 44 int32_t treeLength = 8; 45 std::vector<int8_t> merkleTreeWithPadding = { 1, 1, 1, 1, 1, 1, 1, 1 }; 46 FsVerityDescriptorWithSign descriptorWithSign; 47 ElfSignBlock elfSignBlock(treeLength, merkleTreeWithPadding, descriptorWithSign); 48 std::vector<int8_t> arr; 49 elfSignBlock.ToByteArray(arr); 50 ElfSignBlock block; 51 bool flag = elfSignBlock.FromByteArray(arr, block); 52 53 EXPECT_EQ(flag, false); 54 } 55 56 /** 57 * @tc.name: FromByteArray002 58 * @tc.desc: The return will be false,because the data has wrong fs-verify descriptor type in the ElfSignBlock 59 * @tc.size: MEDIUM 60 * @tc.type: FUNC 61 * @tc.level Level 1 62 * @tc.require: SR000H63TL 63 */ 64 HWTEST_F(ElfSignBlockTest, FromByteArray002, testing::ext::TestSize.Level1) 65 { 66 int32_t treeLength = 8; 67 std::vector<int8_t> merkleTreeWithPadding = { 1, 1, 1, 1, 1, 1, 1, 1 }; 68 FsVerityDescriptorWithSign descriptorWithSign; 69 ElfSignBlock elfSignBlock(treeLength, merkleTreeWithPadding, descriptorWithSign); 70 std::vector<int8_t> arr; 71 elfSignBlock.ToByteArray(arr); 72 arr[24] = 0; 73 ElfSignBlock block; 74 bool flag = elfSignBlock.FromByteArray(arr, block); 75 76 EXPECT_EQ(flag, false); 77 } 78 } // namespace SignatureTools 79 } // namespace OHOS