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 #include "md_impl.h"
16 
17 namespace OHOS {
18     namespace CryptoFramework {
MdImpl(HcfMd * mdObj)19         MdImpl::MdImpl(HcfMd *mdObj)
20         {
21             mdObj_ = mdObj;
22         }
23 
MdUpdate(HcfBlob * input)24         HcfResult MdImpl::MdUpdate(HcfBlob *input)
25         {
26             if (mdObj_ == nullptr) {
27                 LOGE("fail to get md obj!");
28                 return HCF_ERR_MALLOC;
29             }
30             HcfResult res = mdObj_->update(mdObj_, input);
31             return res;
32         }
33 
~MdImpl()34         MdImpl::~MdImpl()
35         {
36             HcfObjDestroy(this->mdObj_);
37         }
38 
MdDoFinal(HcfBlob * output)39         HcfResult MdImpl::MdDoFinal(HcfBlob *output)
40         {
41             if (mdObj_ == nullptr) {
42                 LOGE("fail to get md obj!");
43                 return HCF_ERR_MALLOC;
44             }
45             HcfResult res = mdObj_->doFinal(mdObj_, output);
46             return res;
47         }
48 
GetMdLength(int32_t * errCode)49         uint32_t MdImpl::GetMdLength(int32_t* errCode)
50         {
51             if (mdObj_ == nullptr) {
52                 LOGE("fail to get md obj!");
53                 *errCode = HCF_ERR_MALLOC;
54                 return 0;
55             }
56             uint32_t retLen = mdObj_->getMdLength(mdObj_);
57             *errCode = HCF_SUCCESS;
58             return retLen;
59         }
60     }
61 }