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 "sign_impl.h"
17 
18 namespace OHOS {
19 namespace CryptoFramework {
SignImpl(HcfSign * signObj)20 SignImpl::SignImpl(HcfSign *signObj)
21 {
22     signObj_ = signObj;
23 }
24 
~SignImpl()25 SignImpl::~SignImpl()
26 {
27     HcfObjDestroy(this->signObj_);
28 }
29 
Init(HcfPriKey * priKey)30 HcfResult SignImpl::Init(HcfPriKey *priKey)
31 {
32     if (this->signObj_ == nullptr)  {
33         return HCF_INVALID_PARAMS;
34     }
35     return this->signObj_->init(signObj_, nullptr, priKey);
36 }
37 
Update(HcfBlob * input)38 HcfResult SignImpl::Update(HcfBlob *input)
39 {
40     if (this->signObj_ == nullptr)  {
41         return HCF_INVALID_PARAMS;
42     }
43     return this->signObj_->update(signObj_, input);
44 }
45 
Sign(HcfBlob * input,HcfBlob * output)46 HcfResult SignImpl::Sign(HcfBlob *input, HcfBlob *output)
47 {
48     if (this->signObj_ == nullptr)  {
49         return HCF_INVALID_PARAMS;
50     }
51     return this->signObj_->sign(signObj_, input, output);
52 }
53 
SetSignSpecByNum(int32_t itemValue)54 HcfResult SignImpl::SetSignSpecByNum(int32_t itemValue)
55 {
56     if (this->signObj_ == nullptr)  {
57         return HCF_INVALID_PARAMS;
58     }
59     return this->signObj_->setSignSpecInt(signObj_, PSS_SALT_LEN_INT, itemValue);
60 }
61 
SetSignSpecByArr(HcfBlob itemValue)62 HcfResult SignImpl::SetSignSpecByArr(HcfBlob itemValue)
63 {
64     if (this->signObj_ == nullptr)  {
65         return HCF_INVALID_PARAMS;
66     }
67     return this->signObj_->setSignSpecUint8Array(signObj_, SM2_USER_ID_UINT8ARR, itemValue);
68 }
69 
GetSignSpecString(SignSpecItem item,char * itemValue)70 HcfResult SignImpl::GetSignSpecString(SignSpecItem item, char *itemValue)
71 {
72     if (this->signObj_ == nullptr)  {
73         return HCF_INVALID_PARAMS;
74     }
75     return this->signObj_->getSignSpecString(signObj_, item, &itemValue);
76 }
77 
GetSignSpecNum(SignSpecItem item,int32_t * itemValue)78 HcfResult SignImpl::GetSignSpecNum(SignSpecItem item, int32_t *itemValue)
79 {
80     if (this->signObj_ == nullptr)  {
81         return HCF_INVALID_PARAMS;
82     }
83     return this->signObj_->getSignSpecInt(signObj_, item, itemValue);
84 }
85 }
86 }