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 "key_impl.h" 16 17 namespace OHOS { 18 namespace CryptoFramework { KeyImpl(HcfKey * hcfKey)19 KeyImpl::KeyImpl(HcfKey *hcfKey) 20 { 21 hcfKey_ = hcfKey; 22 } 23 ~KeyImpl()24 KeyImpl::~KeyImpl() {} 25 GetHcfKey() const26 HcfKey *KeyImpl::GetHcfKey() const 27 { 28 return hcfKey_; 29 } 30 GetFormat(int32_t * errCode)31 const char *KeyImpl::GetFormat(int32_t* errCode) 32 { 33 if (hcfKey_ == nullptr) { 34 LOGE("fail to get key obj!"); 35 *errCode = HCF_ERR_MALLOC; 36 return nullptr; 37 } 38 const char *format = hcfKey_->getFormat(hcfKey_); 39 *errCode = HCF_SUCCESS; 40 return format; 41 } 42 GetAlgorithm(int32_t * errCode)43 const char *KeyImpl::GetAlgorithm(int32_t* errCode) 44 { 45 if (hcfKey_ == nullptr) { 46 LOGE("fail to get key obj!"); 47 *errCode = HCF_ERR_MALLOC; 48 return nullptr; 49 } 50 const char *algo = hcfKey_->getAlgorithm(hcfKey_); 51 *errCode = HCF_SUCCESS; 52 return algo; 53 } 54 GetEncoded(HcfBlob * returnBlob)55 HcfResult KeyImpl::GetEncoded(HcfBlob *returnBlob) 56 { 57 if (hcfKey_ == nullptr) { 58 LOGE("fail to get key obj!"); 59 return HCF_ERR_MALLOC; 60 } 61 return hcfKey_->getEncoded(hcfKey_, returnBlob); 62 } 63 } 64 }