HcfResult HcfMdCreate(const char *algoName, HcfMd **md) { if (!IsStrValid(algoName, HCF_MAX_ALGO_NAME_LEN) || (md == NULL)) { LOGE("Invalid input params while creating md!"); return HCF_INVALID_PARAMS; } HcfMdSpiCreateFunc createSpiFunc = FindAbility(algoName); if (createSpiFunc == NULL) { LOGE("Algo not supported!"); return HCF_NOT_SUPPORT; } HcfMdImpl *returnMdApi = (HcfMdImpl *)HcfMalloc(sizeof(HcfMdImpl), 0); if (returnMdApi == NULL) { LOGE("Failed to allocate Md Obj memory!"); return HCF_ERR_MALLOC; } if (strcpy_s(returnMdApi->algoName, HCF_MAX_ALGO_NAME_LEN, algoName) != EOK) { LOGE("Failed to copy algoName!"); HcfFree(returnMdApi); return HCF_ERR_COPY; } HcfMdSpi *spiObj = NULL; HcfResult res = createSpiFunc(algoName, &spiObj); if (res != HCF_SUCCESS) { LOGE("Failed to create spi object!"); HcfFree(returnMdApi); return res; }
时间: 2024-04-27 19:25:30 浏览: 135
(const) char 转CString 详解(字符串类型转换详解,不断补充)
这段代码是用来创建一个HcfMd对象的,其中包括以下步骤:
1. 检查输入参数是否合法;
2. 查找指定算法名对应的能力函数;
3. 分配HcfMdImpl对象的内存空间;
4. 将算法名复制到HcfMdImpl对象的algoName成员中;
5. 调用能力函数创建HcfMdSpi对象;
6. 如果创建失败,释放HcfMdImpl对象并返回错误码。
阅读全文