1/*
2 * Copyright (C) 2023-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#ifndef ATTRIBUTE_H
17#define ATTRIBUTE_H
18
19#include "c_array.h"
20#include "defines.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26typedef enum {
27    /* Root tag */
28    ATTR_ROOT = 100000,
29    /* Result code */
30    ATTR_RESULT_CODE = 100001,
31    /* Tag of signature data in TLV */
32    ATTR_SIGNATURE = 100004,
33    /* Identify mode */
34    ATTR_IDENTIFY_MODE = 100005,
35    /* Tag of templateId data in TLV */
36    ATTR_TEMPLATE_ID = 100006,
37    /* Tag of templateId list data in TLV */
38    ATTR_TEMPLATE_ID_LIST = 100007,
39    /* Expected attribute, tag of remain count in TLV */
40    ATTR_REMAIN_ATTEMPTS = 100009,
41    /* Remain time */
42    ATTR_LOCKOUT_DURATION = 100010,
43    /* Session id, required when decode in C */
44    ATTR_SCHEDULE_ID = 100014,
45    /* Tag of data */
46    ATTR_DATA = 100020,
47    /* Tag of auth subType */
48    ATTR_PIN_SUB_TYPE = 100021,
49    /* Tag of auth schedule mode */
50    ATTR_SCHEDULE_MODE = 100022,
51    /* Tag of property */
52    ATTR_PROPERTY_MODE = 100023,
53    /* Tag of auth type */
54    ATTR_TYPE = 100024,
55    /* Tag of cred id */
56    ATTR_CREDENTIAL_ID = 100025,
57    /* Controller */
58    ATTR_CONTROLLER = 100026,
59    /* calleruid */
60    ATTR_CALLER_UID = 100027,
61    /* result */
62    ATTR_RESULT = 100028,
63    /* capability level */
64    ATTR_CAPABILITY_LEVEL = 100029,
65    /* algorithm setinfo */
66    ATTR_ALGORITHM_INFO = 100030,
67    /* time stamp */
68    ATTR_TIME_STAMP = 100031,
69    /* root secret */
70    ATTR_ROOT_SECRET = 100032,
71    /* attrs */
72    ATTR_ATTRS = 100033,
73    /* pin expired sys time */
74    ATTR_EXPIRED_SYS_TIME = 100034,
75    /* executor matcher */
76    ATTR_EXECUTOR_MATCHER = 100036,
77    /* user id */
78    ATTR_USER_ID = 100041,
79    /* token */
80    ATTR_TOKEN = 100042,
81    /* executor role */
82    ATTR_EXECUTOR_ROLE = 100043,
83    /* esl */
84    ATTR_ESL = 100044,
85    /* VERIFIER udid */
86    ATTR_VERIFIER_UDID = 100045,
87    /* COLLECTOR udid */
88    ATTR_COLLECTOR_UDID = 100046,
89    /* local udid */
90    ATTR_LOCAL_UDID = 100063,
91    /* peer udid */
92    ATTR_PEER_UDID = 100064,
93    /* public key */
94    ATTR_PUBLIC_KEY = 100065,
95    /* Challenge */
96    ATTR_CHALLENGE = 100066,
97    /* executor index */
98    ATTR_EXECUTOR_INDEX = 100067,
99} AttributeKey;
100
101#define MAX_SUB_MSG_NUM 10
102
103typedef void Attribute;
104
105#define MAX_EXECUTOR_MSG_LEN 2048
106
107Attribute *CreateEmptyAttribute(void);
108Attribute *CreateAttributeFromSerializedMsg(const Uint8Array msg);
109void FreeAttribute(Attribute **attribute);
110
111ResultCode GetAttributeSerializedMsg(const Attribute *attribute, Uint8Array *retMsg);
112
113ResultCode GetAttributeUint32(const Attribute *attribute, AttributeKey key, uint32_t *retValue);
114ResultCode SetAttributeUint32(Attribute *attribute, AttributeKey key, const uint32_t value);
115ResultCode GetAttributeInt32(const Attribute *attribute, AttributeKey key, int32_t *retValue);
116ResultCode SetAttributeInt32(Attribute *attribute, AttributeKey key, const int32_t value);
117ResultCode GetAttributeUint64(const Attribute *attribute, AttributeKey key, uint64_t *retValue);
118ResultCode SetAttributeUint64(Attribute *attribute, AttributeKey key, const uint64_t value);
119ResultCode GetAttributeUint8Array(const Attribute *attribute, AttributeKey key, Uint8Array *retData);
120ResultCode SetAttributeUint8Array(Attribute *attribute, AttributeKey key, const Uint8Array data);
121ResultCode GetAttributeUint64Array(const Attribute *attribute, AttributeKey key, Uint64Array *retData);
122ResultCode SetAttributeUint64Array(Attribute *attribute, AttributeKey key, const Uint64Array data);
123
124ResultCode ParseMultiDataSerializedMsg(const Uint8Array msg, Uint8Array *subMsgData, int *subMsgSize);
125ResultCode GetMultiDataSerializedMsg(Uint8Array *sourceArrayMsg, uint32_t size, Uint8Array *retMsg);
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif // ATTRIBUTE_H