1 /*
2  * Copyright (C) 2022 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 ASY_TOKEN_MANAGER_H
17 #define ASY_TOKEN_MANAGER_H
18 
19 #include <stdint.h>
20 #include "alg_defs.h"
21 #include "common_defs.h"
22 #include "string_util.h"
23 
24 typedef struct {
25     Uint8Buff version;
26     Uint8Buff userId;
27     Uint8Buff deviceId;
28     Uint8Buff devicePk;
29 } PkInfo;
30 
31 typedef struct {
32     Uint8Buff pkInfoStr;
33     PkInfo pkInfo;
34     Uint8Buff pkInfoSignature;
35     Uint8Buff serverPk;
36 } AccountToken;
37 DECLARE_HC_VECTOR(AccountTokenVec, AccountToken*)
38 
39 typedef struct {
40     int32_t (*addToken)(int32_t osAccountId, int32_t opCode, const CJson *in);
41     int32_t (*getToken)(int32_t osAccountId, AccountToken *token, const char *userId, const char *deviceId);
42     int32_t (*deleteToken)(int32_t osAccountId, const char *userId, const char *deviceId);
43     int32_t (*getRegisterProof)(int32_t osAccountId, const CJson *in, CJson *out);
44     int32_t (*generateKeyAlias)(const char *userId, const char *deviceId,
45         Uint8Buff *keyAlias, bool isServerPkAlias);
46 } AccountAuthTokenManager;
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 AccountAuthTokenManager *GetAccountAuthTokenManager(void);
53 
54 void InitTokenManager(void);
55 void DestroyTokenManager(void);
56 
57 AccountToken *CreateAccountToken(void);
58 void DestroyAccountToken(AccountToken *token);
59 
60 AccountTokenVec CreateAccountTokenVec(void);
61 void ClearAccountTokenVec(AccountTokenVec *vec);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif