1 Star 0 Fork 0

OpenFDE/platform_system_hwservicemanager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TokenManager.h 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
Steven Moreland 提交于 2019-06-06 12:59 . Use pragma once (for simplicity).
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <android/hidl/token/1.0/ITokenManager.h>
#include <chrono>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <unordered_map>
#include <array>
namespace android {
namespace hidl {
namespace token {
namespace V1_0 {
namespace implementation {
using ::android::hidl::base::V1_0::IBase;
using ::android::hidl::token::V1_0::ITokenManager;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct TokenManager : public ITokenManager {
TokenManager();
// Methods from ::android::hidl::token::V1_0::ITokenManager follow.
Return<void> createToken(const sp<IBase>& store, createToken_cb hidl_cb) override;
Return<bool> unregister(const hidl_vec<uint8_t> &token) override;
Return<sp<IBase>> get(const hidl_vec<uint8_t> &token) override;
private:
static constexpr uint64_t KEY_SIZE = 16;
static constexpr uint64_t TOKEN_ID_NONE = 0;
static bool constantTimeCompare(const hidl_vec<uint8_t> &t1, const hidl_vec<uint8_t> &t2);
static hidl_vec<uint8_t> makeToken(const uint64_t id, const uint8_t *hmac, uint64_t hmacSize);
static uint64_t getTokenId(const hidl_vec<uint8_t> &token);
std::array<uint8_t, KEY_SIZE> mKey;
struct TokenInterface {
sp<IBase> interface;
uint64_t id;
hidl_vec<uint8_t> token; // First eight bytes are tokenId. Remaining bytes are hmac.
};
TokenInterface generateToken(const sp<IBase> &interface);
// verifies token, returns iterator into mMap
std::unordered_map<uint64_t, TokenInterface>::const_iterator
lookupToken(const hidl_vec<uint8_t> &token);
std::unordered_map<uint64_t, TokenInterface> mMap; // map getTokenId(i.token) -> i
uint64_t mTokenIndex = TOKEN_ID_NONE; // last token index
};
} // namespace implementation
} // namespace V1_0
} // namespace token
} // namespace hidl
} // namespace android
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openfde/platform_system_hwservicemanager.git
git@gitee.com:openfde/platform_system_hwservicemanager.git
openfde
platform_system_hwservicemanager
platform_system_hwservicemanager
master

搜索帮助