xref: /base/startup/init/test/mock/hvb/libhvb/auth/hvb.c (revision d9f0492f)
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 <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include "hvb.h"
20
21static struct hvb_cert_data g_testCert[1] = { 0 };
22
23static struct hvb_verified_data g_testVd = {
24    .num_loaded_certs = 1,
25    .certs = &g_testCert[0],
26};
27
28enum hvb_errno hvb_chain_verify(struct hvb_ops *ops, const char *rvt_ptn, const char *const *hash_ptn_list,
29    struct hvb_verified_data **out_vd)
30{
31    char *verifyValue = getenv("VERIFY_VALUE");
32
33    printf("[Replace]:hvb_chain_verify in\n");
34
35    if ((verifyValue == NULL) || (strcmp(verifyValue, "Fail") == 0)) {
36        *out_vd = NULL;
37        return HVB_ERROR_INVALID_ARGUMENT;
38    }
39    if (strcmp(verifyValue, "PartFail") == 0) {
40        *out_vd = &g_testVd;
41        return HVB_ERROR_UNSUPPORTED_VERSION;
42    }
43    if (strcmp(verifyValue, "Succeed") == 0) {
44        *out_vd = &g_testVd;
45        return HVB_OK;
46    }
47
48    return HVB_OK;
49}
50
51void hvb_chain_verify_data_free(struct hvb_verified_data *vd)
52{
53    vd = NULL;
54    return;
55}
56