TokenInterface interface
=
generateToken(store);
-
>
TokenManager::TokenInterface TokenManager::generateToken(const sp<IBase> &interface) {
uint64_t
id
=
+
+
mTokenIndex;
std::array<uint8_t, EVP_MAX_MD_SIZE> hmac;
uint32_t hmacSize;
uint8_t
*
hmacOut
=
HMAC(EVP_sha256(),
mKey.data(), mKey.size(),
(uint8_t
*
) &
id
, sizeof(
id
),
hmac.data(), &hmacSize);
if
(hmacOut
=
=
nullptr ||
hmacOut !
=
hmac.data()) {
ALOGE(
"Generating token failed, got %p."
, hmacOut);
return
{ nullptr, TOKEN_ID_NONE, {} };
}
/
/
only care about the first HMAC_SIZE bytes of the HMAC
const hidl_vec<uint8_t> &token
=
makeToken(
id
, hmac.data(), hmacSize);
return
{ interface,
id
, token };
}
其中
struct TokenInterface {
sp<IBase> interface;
uint64_t
id
;
hidl_vec<uint8_t> token;
/
/
First eight bytes are tokenId. Remaining bytes are hmac.
};
接着
uint64_t
id
=
getTokenId(interface.token);
...
mMap[
id
]
=
interface;