1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef USERIAM_COAUTH_H
17094332d3Sopenharmony_ci#define USERIAM_COAUTH_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include "c_array.h"
20094332d3Sopenharmony_ci#include "defines.h"
21094332d3Sopenharmony_ci#include "pool.h"
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_ci#ifdef __cplusplus
24094332d3Sopenharmony_ciextern "C" {
25094332d3Sopenharmony_ci#endif
26094332d3Sopenharmony_ci
27094332d3Sopenharmony_ci#define INVALID_SESSION_ID 0
28094332d3Sopenharmony_ci#define MAX_EXECUTOR_SIZE 2
29094332d3Sopenharmony_ci#define MAX_SCHEDULE_NUM 51
30094332d3Sopenharmony_ci
31094332d3Sopenharmony_citypedef union AssociateId {
32094332d3Sopenharmony_ci    uint64_t contextId;
33094332d3Sopenharmony_ci    int32_t userId;
34094332d3Sopenharmony_ci} AssociateId;
35094332d3Sopenharmony_ci
36094332d3Sopenharmony_citypedef struct ScheduleParam {
37094332d3Sopenharmony_ci    uint32_t authType;
38094332d3Sopenharmony_ci    ScheduleMode scheduleMode;
39094332d3Sopenharmony_ci    AssociateId associateId;
40094332d3Sopenharmony_ci    Uint64Array *templateIds;
41094332d3Sopenharmony_ci    uint32_t collectorSensorHint;
42094332d3Sopenharmony_ci    uint32_t verifierSensorHint;
43094332d3Sopenharmony_ci    uint32_t executorMatcher;
44094332d3Sopenharmony_ci    int32_t userType;
45094332d3Sopenharmony_ci    uint8_t localUdid[UDID_LEN];
46094332d3Sopenharmony_ci    uint8_t collectorUdid[UDID_LEN];
47094332d3Sopenharmony_ci} ScheduleParam;
48094332d3Sopenharmony_ci
49094332d3Sopenharmony_citypedef struct CoAuthSchedule {
50094332d3Sopenharmony_ci    uint64_t scheduleId;
51094332d3Sopenharmony_ci    uint32_t authType;
52094332d3Sopenharmony_ci    ScheduleMode scheduleMode;
53094332d3Sopenharmony_ci    AssociateId associateId;
54094332d3Sopenharmony_ci    Uint64Array templateIds;
55094332d3Sopenharmony_ci    uint32_t executorSize;
56094332d3Sopenharmony_ci    ExecutorInfoHal executors[MAX_EXECUTOR_SIZE];
57094332d3Sopenharmony_ci    int32_t userType;
58094332d3Sopenharmony_ci} CoAuthSchedule;
59094332d3Sopenharmony_ci
60094332d3Sopenharmony_citypedef struct ScheduleInfoParam {
61094332d3Sopenharmony_ci    uint64_t scheduleId;
62094332d3Sopenharmony_ci    uint32_t authType;
63094332d3Sopenharmony_ci    uint32_t executorMatcher;
64094332d3Sopenharmony_ci    int32_t scheduleMode;
65094332d3Sopenharmony_ci    uint64_t executorIndex;
66094332d3Sopenharmony_ci    Buffer *executorMessages;
67094332d3Sopenharmony_ci    uint8_t localUdid[UDID_LEN];
68094332d3Sopenharmony_ci    uint8_t remoteUdid[UDID_LEN];
69094332d3Sopenharmony_ci} ScheduleInfoParam;
70094332d3Sopenharmony_ci
71094332d3Sopenharmony_citypedef struct AuthResultParam {
72094332d3Sopenharmony_ci    int32_t result;
73094332d3Sopenharmony_ci    int32_t lockoutDuration;
74094332d3Sopenharmony_ci    int32_t remainAttempts;
75094332d3Sopenharmony_ci    int32_t userId;
76094332d3Sopenharmony_ci    Buffer *token;
77094332d3Sopenharmony_ci    Buffer *remoteAuthResultMsg;
78094332d3Sopenharmony_ci    uint8_t localUdid[UDID_LEN];
79094332d3Sopenharmony_ci    uint8_t remoteUdid[UDID_LEN];
80094332d3Sopenharmony_ci} AuthResultParam;
81094332d3Sopenharmony_ci
82094332d3Sopenharmony_ciResultCode InitCoAuth(void);
83094332d3Sopenharmony_civoid DestoryCoAuth(void);
84094332d3Sopenharmony_ci
85094332d3Sopenharmony_ciCoAuthSchedule *GenerateSchedule(const ScheduleParam *param);
86094332d3Sopenharmony_ci
87094332d3Sopenharmony_ciResultCode AddCoAuthSchedule(const CoAuthSchedule *coAuthSchedule);
88094332d3Sopenharmony_ciResultCode RemoveCoAuthSchedule(uint64_t scheduleId);
89094332d3Sopenharmony_ciconst CoAuthSchedule *GetCoAuthSchedule(uint64_t scheduleId);
90094332d3Sopenharmony_ciuint32_t GetScheduleVerifierSensorHint(const CoAuthSchedule *coAuthSchedule);
91094332d3Sopenharmony_civoid DestroyCoAuthSchedule(CoAuthSchedule *coAuthSchedule);
92094332d3Sopenharmony_ciCoAuthSchedule *CopyCoAuthSchedule(const CoAuthSchedule *coAuthSchedule);
93094332d3Sopenharmony_civoid DestroyScheduleNode(void *data);
94094332d3Sopenharmony_cibool IsTemplateArraysValid(const Uint64Array *templateIds);
95094332d3Sopenharmony_ciResultCode CopyTemplateArrays(const Uint64Array *in, Uint64Array *out);
96094332d3Sopenharmony_ci
97094332d3Sopenharmony_ci#ifdef __cplusplus
98094332d3Sopenharmony_ci}
99094332d3Sopenharmony_ci#endif
100094332d3Sopenharmony_ci
101094332d3Sopenharmony_ci#endif
102