1 /*
2 * Copyright (C) 2021 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 "interfaces/hap_verify_result.h"
17
18 #include "util/hap_signing_block_utils.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace Verify {
HapVerifyResult()23 HapVerifyResult::HapVerifyResult()
24 : version(0), publicKeys(), signatures(), pkcs7SignBlock(),
25 pkcs7ProfileBlock(), optionalBlocks(), provisionInfo()
26 {
27 }
28
~HapVerifyResult()29 HapVerifyResult::~HapVerifyResult()
30 {
31 }
32
GetVersion() const33 int32_t HapVerifyResult::GetVersion() const
34 {
35 return version;
36 }
37
SetVersion(int32_t signatureVersion)38 void HapVerifyResult::SetVersion(int32_t signatureVersion)
39 {
40 version = signatureVersion;
41 }
42
SetPkcs7SignBlock(const HapByteBuffer & pkcs7)43 void HapVerifyResult::SetPkcs7SignBlock(const HapByteBuffer& pkcs7)
44 {
45 pkcs7SignBlock = pkcs7;
46 }
47
SetPkcs7ProfileBlock(const HapByteBuffer & pkcs7)48 void HapVerifyResult::SetPkcs7ProfileBlock(const HapByteBuffer& pkcs7)
49 {
50 pkcs7ProfileBlock = pkcs7;
51 }
52
SetOptionalBlocks(const std::vector<OptionalBlock> & option)53 void HapVerifyResult::SetOptionalBlocks(const std::vector<OptionalBlock>& option)
54 {
55 optionalBlocks = option;
56 }
57
GetPublicKey() const58 std::vector<std::string> HapVerifyResult::GetPublicKey() const
59 {
60 return publicKeys;
61 }
62
GetSignature() const63 std::vector<std::string> HapVerifyResult::GetSignature() const
64 {
65 return signatures;
66 }
67
SetPublicKey(const std::vector<std::string> & inputPubkeys)68 void HapVerifyResult::SetPublicKey(const std::vector<std::string>& inputPubkeys)
69 {
70 publicKeys = inputPubkeys;
71 }
72
SetSignature(const std::vector<std::string> & inputSignatures)73 void HapVerifyResult::SetSignature(const std::vector<std::string>& inputSignatures)
74 {
75 signatures = inputSignatures;
76 }
77
GetProperty(std::string & property) const78 int32_t HapVerifyResult::GetProperty(std::string& property) const
79 {
80 return GetBlockFromOptionalBlocks(PROPERTY_BLOB, property);
81 }
82
GetBlockFromOptionalBlocks(int32_t blockType,std::string & block) const83 int32_t HapVerifyResult::GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const
84 {
85 for (unsigned long i = 0; i < optionalBlocks.size(); i++) {
86 if (optionalBlocks[i].optionalType == blockType) {
87 const HapByteBuffer& option = optionalBlocks[i].optionalBlockValue;
88 block += std::string(option.GetBufferPtr(), option.GetCapacity());
89 return GET_SUCCESS;
90 }
91 }
92 return NO_THIS_BLOCK_IN_PACKAGE;
93 }
94
SetProvisionInfo(const ProvisionInfo & info)95 void HapVerifyResult::SetProvisionInfo(const ProvisionInfo &info)
96 {
97 provisionInfo = info;
98 }
99
GetProvisionInfo() const100 ProvisionInfo HapVerifyResult::GetProvisionInfo() const
101 {
102 return provisionInfo;
103 }
104 } // namespace Verify
105 } // namespace Security
106 } // namespace OHOS
107