blob: edb667e0565c4868d187b3f460578a61edf9b7e8 [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 Morelandec50fdf2018-07-17 14:56:20 -070017#pragma once
Steven Moreland0e4be1e2017-04-18 19:50:29 -070018
19#include <string>
20#include <vector>
21
22namespace android {
23
24struct Hash {
Steven Moreland81bcf682017-08-23 17:16:21 -070025 static const std::vector<uint8_t> kEmptyHash;
26
Steven Moreland5bdfa702017-04-18 23:20:39 -070027 // path to .hal file
Steven Morelandec50fdf2018-07-17 14:56:20 -070028 static const Hash& getHash(const std::string& path);
Steven Moreland81bcf682017-08-23 17:16:21 -070029 static void clearHash(const std::string& path);
Steven Moreland0e4be1e2017-04-18 19:50:29 -070030
Steven Moreland5bdfa702017-04-18 23:20:39 -070031 // returns matching hashes of interfaceName in path
32 // path is something like hardware/interfaces/current.txt
33 // interfaceName is something like android.hardware.foo@1.0::IFoo
Steven Moreland566b0e92018-02-16 13:51:33 -080034 static std::vector<std::string> lookupHash(const std::string& path,
35 const std::string& interfaceName, std::string* err,
36 bool* fileExists = nullptr);
Steven Moreland218625a2017-04-18 22:31:50 -070037
Steven Morelandec50fdf2018-07-17 14:56:20 -070038 static std::string hexString(const std::vector<uint8_t>& hash);
Steven Moreland0e4be1e2017-04-18 19:50:29 -070039 std::string hexString() const;
40
Steven Morelandec50fdf2018-07-17 14:56:20 -070041 const std::vector<uint8_t>& raw() const;
42 const std::string& getPath() const;
Steven Moreland0e4be1e2017-04-18 19:50:29 -070043
Steven Morelandec50fdf2018-07-17 14:56:20 -070044 private:
45 Hash(const std::string& path);
Steven Moreland0e4be1e2017-04-18 19:50:29 -070046
Steven Moreland81bcf682017-08-23 17:16:21 -070047 static Hash& getMutableHash(const std::string& path);
48
Steven Moreland0e4be1e2017-04-18 19:50:29 -070049 const std::string mPath;
Steven Moreland81bcf682017-08-23 17:16:21 -070050 std::vector<uint8_t> mHash;
Steven Moreland0e4be1e2017-04-18 19:50:29 -070051};
52
53} // namespace android