17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci#ifndef NATIVE_HUKS_PARAM_H 177777dab0Sopenharmony_ci#define NATIVE_HUKS_PARAM_H 187777dab0Sopenharmony_ci 197777dab0Sopenharmony_ci/** 207777dab0Sopenharmony_ci * @addtogroup HuksParamSetApi 217777dab0Sopenharmony_ci * @{ 227777dab0Sopenharmony_ci * 237777dab0Sopenharmony_ci * @brief Defines the capabilities of OpenHarmony Universal KeyStore (HUKS) parameter sets. 247777dab0Sopenharmony_ci * The HUKS APIs can be used to perform parameter set lifecycle management, 257777dab0Sopenharmony_ci * including initializing a parameter set, adding parameters to a parameter set, constructing 267777dab0Sopenharmony_ci * a parameter set, and destroying a parameter set. 277777dab0Sopenharmony_ci * They can also be used to obtain parameters, copy parameter sets, and check parameter validity. 287777dab0Sopenharmony_ci * 297777dab0Sopenharmony_ci * @syscap SystemCapability.Security.Huks 307777dab0Sopenharmony_ci * @since 9 317777dab0Sopenharmony_ci * @version 1.0 327777dab0Sopenharmony_ci */ 337777dab0Sopenharmony_ci 347777dab0Sopenharmony_ci/** 357777dab0Sopenharmony_ci * @file native_huks_param.h 367777dab0Sopenharmony_ci * 377777dab0Sopenharmony_ci * @brief Provides APIs for constructing, using, and destroying parameter sets. 387777dab0Sopenharmony_ci * 397777dab0Sopenharmony_ci * include "huks/include/native_huks_type.h" 407777dab0Sopenharmony_ci * @kit UniversalKeystoreKit 417777dab0Sopenharmony_ci * @since 9 427777dab0Sopenharmony_ci * @version 1.0 437777dab0Sopenharmony_ci */ 447777dab0Sopenharmony_ci 457777dab0Sopenharmony_ci#include "native_huks_type.h" 467777dab0Sopenharmony_ci 477777dab0Sopenharmony_ci#ifdef __cplusplus 487777dab0Sopenharmony_ciextern "C" { 497777dab0Sopenharmony_ci#endif 507777dab0Sopenharmony_ci 517777dab0Sopenharmony_ci/** 527777dab0Sopenharmony_ci * @brief Initializes a parameter set. 537777dab0Sopenharmony_ci * 547777dab0Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to initialize. 557777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the initialization is successful. 567777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 577777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If the paramset is null. 587777dab0Sopenharmony_ci * @since 9 597777dab0Sopenharmony_ci * @version 1.0 607777dab0Sopenharmony_ci */ 617777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet); 627777dab0Sopenharmony_ci 637777dab0Sopenharmony_ci/** 647777dab0Sopenharmony_ci * @brief Adds parameters to a parameter set. 657777dab0Sopenharmony_ci * 667777dab0Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to which parameters are to be added. 677777dab0Sopenharmony_ci * @param params Indicates the pointer to the array of parameters to add. 687777dab0Sopenharmony_ci * @param paramCnt Indicates the number of parameters to add. 697777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 707777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If params is null or paramSet is invalid. 717777dab0Sopenharmony_ci * @since 9 727777dab0Sopenharmony_ci * @version 1.0 737777dab0Sopenharmony_ci */ 747777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, 757777dab0Sopenharmony_ci const struct OH_Huks_Param *params, uint32_t paramCnt); 767777dab0Sopenharmony_ci 777777dab0Sopenharmony_ci/** 787777dab0Sopenharmony_ci * @brief Constructs a parameter set. 797777dab0Sopenharmony_ci * 807777dab0Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to construct. 817777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 827777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 837777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 847777dab0Sopenharmony_ci * @since 9 857777dab0Sopenharmony_ci * @version 1.0 867777dab0Sopenharmony_ci */ 877777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet); 887777dab0Sopenharmony_ci 897777dab0Sopenharmony_ci/** 907777dab0Sopenharmony_ci * @brief Destroys a parameter set. 917777dab0Sopenharmony_ci * 927777dab0Sopenharmony_ci * @param paramSet Indicates the double pointer to the parameter set to destroy. 937777dab0Sopenharmony_ci * @since 9 947777dab0Sopenharmony_ci * @version 1.0 957777dab0Sopenharmony_ci */ 967777dab0Sopenharmony_civoid OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet); 977777dab0Sopenharmony_ci 987777dab0Sopenharmony_ci/** 997777dab0Sopenharmony_ci * @brief Copies a parameter set (deep copy). 1007777dab0Sopenharmony_ci * 1017777dab0Sopenharmony_ci * @param fromParamSet Indicates the pointer to the parameter set to copy. 1027777dab0Sopenharmony_ci * @param fromParamSetSize Indicates the memory size occupied by the source parameter set. 1037777dab0Sopenharmony_ci * @param paramSet Indicates the double pointer to the new parameter set generated. 1047777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful. 1057777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If fromParamSet or fromParamSetSize 1067777dab0Sopenharmony_ci * or paramSet is invalid. 1077777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 1087777dab0Sopenharmony_ci * @since 9 1097777dab0Sopenharmony_ci * @version 1.0 1107777dab0Sopenharmony_ci */ 1117777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, 1127777dab0Sopenharmony_ci uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet); 1137777dab0Sopenharmony_ci 1147777dab0Sopenharmony_ci/** 1157777dab0Sopenharmony_ci * @brief Obtains parameters from a parameter set. 1167777dab0Sopenharmony_ci * 1177777dab0Sopenharmony_ci * @param paramSet Indicates the pointer to the target parameter set. 1187777dab0Sopenharmony_ci * @param tag Indicates the value of the parameter to be obtained. 1197777dab0Sopenharmony_ci * @param param Indicates the double pointer to the parameter obtained. 1207777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the operation is successful, 1217777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet or param is invalid, 1227777dab0Sopenharmony_ci * or if the param doesn't exist in the pararmset. 1237777dab0Sopenharmony_ci * @since 9 1247777dab0Sopenharmony_ci * @version 1.0 1257777dab0Sopenharmony_ci */ 1267777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, 1277777dab0Sopenharmony_ci struct OH_Huks_Param **param); 1287777dab0Sopenharmony_ci 1297777dab0Sopenharmony_ci/** 1307777dab0Sopenharmony_ci * @brief Refreshes data of the <b>Blob</b> type in a parameter set. 1317777dab0Sopenharmony_ci * 1327777dab0Sopenharmony_ci * @param paramSet Indicates the pointer to the target parameter set. 1337777dab0Sopenharmony_ci * @param isCopy Specifies whether to copy the data of the <b>Blob</b> type to the parameter set. 1347777dab0Sopenharmony_ci * If yes, the data of the <b>Blob</b> type will be copied to the parameter set. 1357777dab0Sopenharmony_ci * Otherwise, only the address of the <b>Blob</b> data will be refreshed. 1367777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If operation is successful. 1377777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 1387777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_INSUFFICIENT_MEMORY} 12000014 - If the memory is insufficient. 1397777dab0Sopenharmony_ci * @since 9 1407777dab0Sopenharmony_ci * @version 1.0 1417777dab0Sopenharmony_ci */ 1427777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy); 1437777dab0Sopenharmony_ci 1447777dab0Sopenharmony_ci/** 1457777dab0Sopenharmony_ci * @brief Checks whether the parameters in a parameter set are valid. 1467777dab0Sopenharmony_ci * 1477777dab0Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to check. 1487777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the parameters in the parameter set are valid. 1497777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid or 1507777dab0Sopenharmony_ci * the parameter set has invalid, duplicate, or incorrect tags. 1517777dab0Sopenharmony_ci * @since 9 1527777dab0Sopenharmony_ci * @version 1.0 1537777dab0Sopenharmony_ci */ 1547777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_IsParamSetTagValid(const struct OH_Huks_ParamSet *paramSet); 1557777dab0Sopenharmony_ci 1567777dab0Sopenharmony_ci/** 1577777dab0Sopenharmony_ci * @brief Checks whether a parameter set is of the valid size. 1587777dab0Sopenharmony_ci * 1597777dab0Sopenharmony_ci * @param paramSet Indicates the pointer to the parameter set to check. 1607777dab0Sopenharmony_ci * @param size Indicates the memory size occupied by the parameter set. 1617777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the parameter set is of the valid size. 1627777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If paramSet is invalid. 1637777dab0Sopenharmony_ci * @since 9 1647777dab0Sopenharmony_ci * @version 1.0 1657777dab0Sopenharmony_ci */ 1667777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_IsParamSetValid(const struct OH_Huks_ParamSet *paramSet, uint32_t size); 1677777dab0Sopenharmony_ci 1687777dab0Sopenharmony_ci/** 1697777dab0Sopenharmony_ci * @brief Checks whether two parameters are the same. 1707777dab0Sopenharmony_ci * 1717777dab0Sopenharmony_ci * @param baseParam Indicates the pointer to the first parameter. 1727777dab0Sopenharmony_ci * @param param Indicates the pointer to the second parameter. 1737777dab0Sopenharmony_ci * @return {@link OH_Huks_ErrCode#OH_HUKS_SUCCESS} 0 - If the two parameters are the same. 1747777dab0Sopenharmony_ci * {@link OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT} 401 - If one of the paramSet is invalid, 1757777dab0Sopenharmony_ci * or if the params don't match, or if the tag inside is invalid. 1767777dab0Sopenharmony_ci * @since 9 1777777dab0Sopenharmony_ci * @version 1.0 1787777dab0Sopenharmony_ci */ 1797777dab0Sopenharmony_cistruct OH_Huks_Result OH_Huks_CheckParamMatch(const struct OH_Huks_Param *baseParam, const struct OH_Huks_Param *param); 1807777dab0Sopenharmony_ci 1817777dab0Sopenharmony_ci#ifdef __cplusplus 1827777dab0Sopenharmony_ci} 1837777dab0Sopenharmony_ci#endif 1847777dab0Sopenharmony_ci 1857777dab0Sopenharmony_ci/** @} */ 1867777dab0Sopenharmony_ci#endif /* NATIVE_HUKS_PARAM_H */ 187