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 "mac_impl.h"
17 
18 namespace OHOS {
19     namespace CryptoFramework {
MacImpl(HcfMac * macObj)20         MacImpl::MacImpl(HcfMac *macObj)
21         {
22             macObj_ = macObj;
23         }
24 
~MacImpl()25         MacImpl::~MacImpl()
26         {
27             HcfObjDestroy(this->macObj_);
28         }
29 
MacInit(HcfSymKey * symKey)30         HcfResult MacImpl::MacInit(HcfSymKey *symKey)
31         {
32             if (macObj_ == nullptr) {
33                 LOGE("fail to get mac obj!");
34                 return HCF_ERR_MALLOC;
35             }
36             HcfResult res = macObj_->init(macObj_, symKey);
37             return res;
38         }
39 
MacUpdate(HcfBlob * input)40         HcfResult MacImpl::MacUpdate(HcfBlob *input)
41         {
42             if (macObj_ == nullptr) {
43                 LOGE("fail to get mac obj!");
44                 return HCF_ERR_MALLOC;
45             }
46             HcfResult res = macObj_->update(macObj_, input);
47             return res;
48         }
49 
MacDoFinal(HcfBlob * output)50         HcfResult MacImpl::MacDoFinal(HcfBlob *output)
51         {
52             if (macObj_ == nullptr) {
53                 LOGE("fail to get mac obj!");
54                 return HCF_ERR_MALLOC;
55             }
56             HcfResult res = macObj_->doFinal(macObj_, output);
57             return res;
58         }
59 
GetMacLength()60         uint32_t MacImpl::GetMacLength()
61         {
62             if (macObj_ == nullptr) {
63                 LOGE("fail to get mac obj!");
64                 return HCF_ERR_MALLOC;
65             }
66             uint32_t retLen = macObj_->getMacLength(macObj_);
67             return retLen;
68         }
69 
70     }
71 }