Move hashing into its own folder.
Test: hidl's run_all_host_tests.sh
Change-Id: I5573edef59797cc8353d793759df0fbf74827939
diff --git a/Android.bp b/Android.bp
index b7b1481..561476b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -49,26 +49,6 @@
},
}
-//
-// libhidl-gen-hash
-//
-cc_library {
- name: "libhidl-gen-hash",
- host_supported: true,
- defaults: ["hidl-gen-defaults"],
- srcs: ["Hash.cpp"],
- local_include_dirs: ["include_hash/hidl-hash"],
- export_include_dirs: ["include_hash"],
- shared_libs: [
- "libbase",
- "libcrypto",
- "libssl",
- ],
-}
-
-//
-// libhidl-gen
-//
cc_library_host_shared {
name: "libhidl-gen",
defaults: ["hidl-gen-defaults"],
@@ -112,10 +92,6 @@
export_include_dirs: ["."], // for tests
}
-//
-// libhidl-gen-ast
-//
-
cc_library_host_shared {
name: "libhidl-gen-ast",
defaults: ["hidl-gen-defaults"],
@@ -145,9 +121,6 @@
export_include_dirs: ["."], // for tests
}
-//
-// hidl-gen
-//
cc_binary_host {
name: "hidl-gen",
defaults: ["hidl-gen-defaults"],
diff --git a/hashing/Android.bp b/hashing/Android.bp
new file mode 100644
index 0000000..9f63a27
--- /dev/null
+++ b/hashing/Android.bp
@@ -0,0 +1,26 @@
+// Copyright (C) 2018 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.
+
+cc_library {
+ name: "libhidl-gen-hash",
+ host_supported: true,
+ defaults: ["hidl-gen-defaults"],
+ srcs: ["Hash.cpp"],
+ export_include_dirs: ["include"],
+ shared_libs: [
+ "libbase",
+ "libcrypto",
+ "libssl",
+ ],
+}
diff --git a/Hash.cpp b/hashing/Hash.cpp
similarity index 78%
rename from Hash.cpp
rename to hashing/Hash.cpp
index 7eb315b..e88ce17 100644
--- a/Hash.cpp
+++ b/hashing/Hash.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "Hash.h"
+#include <hidl-hash/Hash.h>
#include <algorithm>
#include <fstream>
@@ -50,7 +50,7 @@
getMutableHash(path).mHash = kEmptyHash;
}
-static std::vector<uint8_t> sha256File(const std::string &path) {
+static std::vector<uint8_t> sha256File(const std::string& path) {
std::ifstream stream(path);
std::stringstream fileStream;
fileStream << stream.rdbuf();
@@ -58,17 +58,14 @@
std::vector<uint8_t> ret = std::vector<uint8_t>(SHA256_DIGEST_LENGTH);
- SHA256(reinterpret_cast<const uint8_t *>(fileContent.c_str()),
- fileContent.size(), ret.data());
+ SHA256(reinterpret_cast<const uint8_t*>(fileContent.c_str()), fileContent.size(), ret.data());
return ret;
}
-Hash::Hash(const std::string &path)
- : mPath(path),
- mHash(sha256File(path)) {}
+Hash::Hash(const std::string& path) : mPath(path), mHash(sha256File(path)) {}
-std::string Hash::hexString(const std::vector<uint8_t> &hash) {
+std::string Hash::hexString(const std::vector<uint8_t>& hash) {
std::ostringstream s;
s << std::hex << std::setfill('0');
for (uint8_t i : hash) {
@@ -81,11 +78,11 @@
return hexString(mHash);
}
-const std::vector<uint8_t> &Hash::raw() const {
+const std::vector<uint8_t>& Hash::raw() const {
return mHash;
}
-const std::string &Hash::getPath() const {
+const std::string& Hash::getPath() const {
return mPath;
}
@@ -94,14 +91,11 @@
#define SPACES " +"
#define MAYBE_SPACES " *"
#define OPTIONAL_COMMENT "(?:#.*)?"
-static const std::regex kHashLine(
- "(?:"
- MAYBE_SPACES HASH SPACES FQNAME MAYBE_SPACES
- ")?"
- OPTIONAL_COMMENT);
+static const std::regex kHashLine("(?:" MAYBE_SPACES HASH SPACES FQNAME MAYBE_SPACES
+ ")?" OPTIONAL_COMMENT);
struct HashFile {
- static const HashFile *parse(const std::string &path, std::string *err) {
+ static const HashFile* parse(const std::string& path, std::string* err) {
static std::map<std::string, HashFile*> hashfiles;
auto it = hashfiles.find(path);
@@ -112,7 +106,7 @@
return it->second;
}
- std::vector<std::string> lookup(const std::string &fqName) const {
+ std::vector<std::string> lookup(const std::string& fqName) const {
auto it = hashes.find(fqName);
if (it == hashes.end()) {
@@ -122,18 +116,18 @@
return it->second;
}
-private:
- static HashFile *readHashFile(const std::string &path, std::string *err) {
+ private:
+ static HashFile* readHashFile(const std::string& path, std::string* err) {
std::ifstream stream(path);
if (!stream) {
return nullptr;
}
- HashFile *file = new HashFile();
+ HashFile* file = new HashFile();
file->path = path;
std::string line;
- while(std::getline(stream, line)) {
+ while (std::getline(stream, line)) {
std::smatch match;
bool valid = std::regex_match(line, match, kHashLine);
@@ -164,13 +158,13 @@
}
std::string path;
- std::map<std::string,std::vector<std::string>> hashes;
+ std::map<std::string, std::vector<std::string>> hashes;
};
std::vector<std::string> Hash::lookupHash(const std::string& path, const std::string& interfaceName,
std::string* err, bool* fileExists) {
*err = "";
- const HashFile *file = HashFile::parse(path, err);
+ const HashFile* file = HashFile::parse(path, err);
if (file == nullptr || err->size() > 0) {
if (fileExists != nullptr) *fileExists = false;
@@ -182,4 +176,4 @@
return file->lookup(interfaceName);
}
-} // android
+} // namespace android
diff --git a/include_hash/hidl-hash/Hash.h b/hashing/include/hidl-hash/Hash.h
similarity index 80%
rename from include_hash/hidl-hash/Hash.h
rename to hashing/include/hidl-hash/Hash.h
index e443ef5..edb667e 100644
--- a/include_hash/hidl-hash/Hash.h
+++ b/hashing/include/hidl-hash/Hash.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef HIDL_GEN_HASH_HASH_H_
-#define HIDL_GEN_HASH_HASH_H_
+#pragma once
#include <string>
#include <vector>
@@ -26,7 +25,7 @@
static const std::vector<uint8_t> kEmptyHash;
// path to .hal file
- static const Hash &getHash(const std::string &path);
+ static const Hash& getHash(const std::string& path);
static void clearHash(const std::string& path);
// returns matching hashes of interfaceName in path
@@ -36,14 +35,14 @@
const std::string& interfaceName, std::string* err,
bool* fileExists = nullptr);
- static std::string hexString(const std::vector<uint8_t> &hash);
+ static std::string hexString(const std::vector<uint8_t>& hash);
std::string hexString() const;
- const std::vector<uint8_t> &raw() const;
- const std::string &getPath() const;
+ const std::vector<uint8_t>& raw() const;
+ const std::string& getPath() const;
-private:
- Hash(const std::string &path);
+ private:
+ Hash(const std::string& path);
static Hash& getMutableHash(const std::string& path);
@@ -52,6 +51,3 @@
};
} // namespace android
-
-#endif // HIDL_GEN_HASH_HASH_H_
-