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 AUTH_SESSION_KEY_H 17 #define AUTH_SESSION_KEY_H 18 19 #include "auth_interface.h" 20 #include "common_list.h" 21 #include "softbus_adapter_crypto.h" 22 #include "softbus_def.h" 23 #include "auth_session_key_struct.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif 30 31 void InitSessionKeyList(SessionKeyList *list); 32 void DestroySessionKeyList(SessionKeyList *list); 33 int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList); 34 35 uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type); 36 bool HasSessionKey(const SessionKeyList *list); 37 AuthLinkType GetSessionKeyTypeByIndex(const SessionKeyList *list, int32_t index); 38 int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key, AuthLinkType type, 39 bool isOldKey); 40 int32_t SetSessionKeyAvailable(SessionKeyList *list, int32_t index); 41 int32_t GetLatestSessionKey(const SessionKeyList *list, AuthLinkType type, int32_t *index, SessionKey *key); 42 int32_t GetSessionKeyByIndex(const SessionKeyList *list, int32_t index, AuthLinkType type, SessionKey *key); 43 int32_t SetSessionKeyAuthLinkType(const SessionKeyList *list, int32_t index, AuthLinkType type); 44 bool CheckSessionKeyListExistType(const SessionKeyList *list, AuthLinkType type); 45 bool CheckSessionKeyListHasOldKey(const SessionKeyList *list, AuthLinkType type); 46 int32_t ClearOldKey(const SessionKeyList *list, AuthLinkType type); 47 void RemoveSessionkeyByIndex(SessionKeyList *list, int32_t index, AuthLinkType type); 48 void ClearSessionkeyByAuthLinkType(int64_t authId, SessionKeyList *list, AuthLinkType type); 49 50 int32_t EncryptInner(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo, 51 uint8_t **outData, uint32_t *outLen); 52 int32_t DecryptInner(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo, 53 uint8_t **outData, uint32_t *outLen); 54 55 int32_t EncryptData(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo, 56 uint8_t *outData, uint32_t *outLen); 57 int32_t DecryptData(const SessionKeyList *list, AuthLinkType type, const InDataInfo *inDataInfo, 58 uint8_t *outData, uint32_t *outLen); 59 60 void ScheduleUpdateSessionKey(AuthHandle authHandle, uint64_t delatMs); 61 void CancelUpdateSessionKey(int64_t authId); 62 63 /* For Debug */ 64 void DumpSessionkeyList(const SessionKeyList *list); 65 66 #ifdef __cplusplus 67 #if __cplusplus 68 } 69 #endif 70 #endif 71 #endif /* AUTH_SESSION_KEY_H */ 72