1 /*
2  * Copyright (c) 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 "verify_impl.h"
17 
18 namespace OHOS {
19 namespace CryptoFramework {
VerifyImpl(HcfVerify * verify)20 VerifyImpl::VerifyImpl(HcfVerify *verify)
21 {
22     this->verify_ = verify;
23 }
24 
~VerifyImpl()25 VerifyImpl::~VerifyImpl()
26 {
27     HcfObjDestroy(this->verify_);
28 }
29 
Init(HcfPubKey * pubKey)30 HcfResult VerifyImpl::Init(HcfPubKey *pubKey)
31 {
32     if (this->verify_ == nullptr)  {
33         return HCF_INVALID_PARAMS;
34     }
35     return this->verify_->init(verify_, nullptr, pubKey);
36 }
37 
Update(HcfBlob * input)38 HcfResult VerifyImpl::Update(HcfBlob *input)
39 {
40     if (this->verify_ == nullptr)  {
41         return HCF_INVALID_PARAMS;
42     }
43     return this->verify_->update(verify_, input);
44 }
45 
Verify(HcfBlob * data,HcfBlob signatureData,int32_t * errCode)46 bool VerifyImpl::Verify(HcfBlob *data, HcfBlob signatureData, int32_t *errCode)
47 {
48     if (this->verify_ == nullptr)  {
49         *errCode = HCF_INVALID_PARAMS;
50         return false;
51     }
52     *errCode = HCF_SUCCESS;
53     return this->verify_->verify(verify_, data, &signatureData);
54 }
55 
Recover(HcfBlob input,HcfBlob * output)56 HcfResult VerifyImpl::Recover(HcfBlob input, HcfBlob *output)
57 {
58     if (this->verify_ == nullptr)  {
59         return HCF_INVALID_PARAMS;
60     }
61     return this->verify_->recover(verify_, &input, output);
62 }
63 
SetVerifySpecByNum(int32_t itemValue)64 HcfResult VerifyImpl::SetVerifySpecByNum(int32_t itemValue)
65 {
66     if (this->verify_ == nullptr)  {
67         return HCF_INVALID_PARAMS;
68     }
69     return this->verify_->setVerifySpecInt(verify_, PSS_SALT_LEN_INT, itemValue);
70 }
71 
SetVerifySpecByArr(HcfBlob itemValue)72 HcfResult VerifyImpl::SetVerifySpecByArr(HcfBlob itemValue)
73 {
74     if (this->verify_ == nullptr)  {
75         return HCF_INVALID_PARAMS;
76     }
77     return this->verify_->setVerifySpecUint8Array(verify_, SM2_USER_ID_UINT8ARR, itemValue);
78 }
79 
GetVerifySpecString(SignSpecItem item,char * itemValue)80 HcfResult VerifyImpl::GetVerifySpecString(SignSpecItem item, char *itemValue)
81 {
82     if (this->verify_ == nullptr)  {
83         return HCF_INVALID_PARAMS;
84     }
85     return this->verify_->getVerifySpecString(verify_, item, &itemValue);
86 }
87 
GetVerifySpecNum(SignSpecItem item,int32_t * itemValue)88 HcfResult VerifyImpl::GetVerifySpecNum(SignSpecItem item, int32_t *itemValue)
89 {
90     if (this->verify_ == nullptr)  {
91         return HCF_INVALID_PARAMS;
92     }
93     return this->verify_->getVerifySpecInt(verify_, item, itemValue);
94 }
95 }
96 }