blob: 40cc5bf7e30602049c5e99bb5955e5fba2d75d38 [file] [log] [blame]
Steven Moreland0e4be1e2017-04-18 19:50:29 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Steven Moreland5bdfa702017-04-18 23:20:39 -070017#ifndef HIDL_GEN_HASH_HASH_H_
18#define HIDL_GEN_HASH_HASH_H_
Steven Moreland0e4be1e2017-04-18 19:50:29 -070019
20#include <string>
21#include <vector>
22
23namespace android {
24
25struct Hash {
Steven Moreland81bcf682017-08-23 17:16:21 -070026 static const std::vector<uint8_t> kEmptyHash;
27
Steven Moreland5bdfa702017-04-18 23:20:39 -070028 // path to .hal file
Steven Moreland0e4be1e2017-04-18 19:50:29 -070029 static const Hash &getHash(const std::string &path);
Steven Moreland81bcf682017-08-23 17:16:21 -070030 static void clearHash(const std::string& path);
Steven Moreland0e4be1e2017-04-18 19:50:29 -070031
Steven Moreland5bdfa702017-04-18 23:20:39 -070032 // returns matching hashes of interfaceName in path
33 // path is something like hardware/interfaces/current.txt
34 // interfaceName is something like android.hardware.foo@1.0::IFoo
Steven Moreland218625a2017-04-18 22:31:50 -070035 static std::vector<std::string> lookupHash(const std::string &path,
36 const std::string &interfaceName,
37 std::string *err);
38
Tri Vo59ce7422017-04-26 10:53:54 -070039 static std::string hexString(const std::vector<uint8_t> &hash);
Steven Moreland0e4be1e2017-04-18 19:50:29 -070040 std::string hexString() const;
41
42 const std::vector<uint8_t> &raw() const;
43 const std::string &getPath() const;
44
45private:
46 Hash(const std::string &path);
47
Steven Moreland81bcf682017-08-23 17:16:21 -070048 static Hash& getMutableHash(const std::string& path);
49
Steven Moreland0e4be1e2017-04-18 19:50:29 -070050 const std::string mPath;
Steven Moreland81bcf682017-08-23 17:16:21 -070051 std::vector<uint8_t> mHash;
Steven Moreland0e4be1e2017-04-18 19:50:29 -070052};
53
54} // namespace android
55
Steven Moreland5bdfa702017-04-18 23:20:39 -070056#endif // HIDL_GEN_HASH_HASH_H_
Steven Moreland0e4be1e2017-04-18 19:50:29 -070057