From 5f238a65f6f2b74b602317e6ce73d601010915ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Kri=C5=A1to?= Date: Wed, 26 Jul 2023 22:39:41 +0200 Subject: [PATCH] Remove boringssl dependency. Replace sha256 with absl::Hash. --- WORKSPACE | 9 --------- verilog/tools/kythe/BUILD | 2 +- verilog/tools/kythe/kzip_creator.cc | 14 +++++--------- verilog/tools/kythe/kzip_creator.h | 2 +- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 7304548cd..089199712 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -230,12 +230,3 @@ maybe( "https://zlib.net/fossils/zlib-1.2.13.tar.gz", ], ) - -# Only needed for sha256; Version taken from branch with bazel rules -# https://github.com/google/boringssl/tree/master-with-bazel -http_archive( - name = "com_google_boringssl", - sha256 = "8b28b030652d1b5e0f8de306e8bdc1b67f7164c2ec889056a0c13e78ba615a34", - strip_prefix = "boringssl-342e805bc1f5dfdd650e3f031686d6c939b095d9", - urls = ["https://github.com/google/boringssl/archive/342e805bc1f5dfdd650e3f031686d6c939b095d9.zip"], -) diff --git a/verilog/tools/kythe/BUILD b/verilog/tools/kythe/BUILD index 42d1a636e..e6e86b433 100644 --- a/verilog/tools/kythe/BUILD +++ b/verilog/tools/kythe/BUILD @@ -277,9 +277,9 @@ cc_library( "//common/util:file-util", "//common/util:simple-zip", "//third_party/proto/kythe:analysis_cc_proto", + "@com_google_absl//absl/hash", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", - "@com_google_boringssl//:crypto", ], ) diff --git a/verilog/tools/kythe/kzip_creator.cc b/verilog/tools/kythe/kzip_creator.cc index b6b179a14..8ad526d46 100644 --- a/verilog/tools/kythe/kzip_creator.cc +++ b/verilog/tools/kythe/kzip_creator.cc @@ -19,12 +19,12 @@ #include #include +#include "absl/hash/hash.h" #include "absl/status/status.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "common/util/file_util.h" #include "common/util/simple_zip.h" -#include "openssl/sha.h" #include "third_party/proto/kythe/analysis.pb.h" namespace verilog { @@ -34,12 +34,8 @@ namespace { constexpr absl::string_view kProtoUnitRoot = "root/pbunits/"; constexpr absl::string_view kFileRoot = "root/files/"; -std::string SHA256Digest(absl::string_view content) { - std::array buf; - ::SHA256(reinterpret_cast(content.data()), - content.size(), buf.data()); - return absl::BytesToHexString(absl::string_view( - reinterpret_cast(buf.data()), buf.size())); +std::string Digest(absl::string_view content) { + return absl::StrCat(absl::HashOf(content)); } constexpr int kKZipCompressionLevel = 9; @@ -58,7 +54,7 @@ KzipCreator::KzipCreator(absl::string_view output_path) std::string KzipCreator::AddSourceFile(absl::string_view path, absl::string_view content) { - std::string digest = SHA256Digest(content); + std::string digest = Digest(content); const std::string archive_path = verible::file::JoinPath(kFileRoot, digest); archive_.AddFile(archive_path, verible::zip::MemoryByteSource(content)); return digest; @@ -70,7 +66,7 @@ absl::Status KzipCreator::AddCompilationUnit( if (!unit.SerializeToString(&content)) { return absl::InternalError("Failed to serialize the compilation unit"); } - const std::string digest = SHA256Digest(content); + const std::string digest = Digest(content); const std::string archive_path = verible::file::JoinPath(kProtoUnitRoot, digest); archive_.AddFile(archive_path, verible::zip::MemoryByteSource(content)); diff --git a/verilog/tools/kythe/kzip_creator.h b/verilog/tools/kythe/kzip_creator.h index 7b61dc8b8..6e4b01f2f 100644 --- a/verilog/tools/kythe/kzip_creator.h +++ b/verilog/tools/kythe/kzip_creator.h @@ -34,7 +34,7 @@ class KzipCreator final { // Initializes the archive. Crashes if initialization fails. explicit KzipCreator(absl::string_view output_path); - // Adds source code file to the Kzip. Returns its SHA digest. + // Adds source code file to the Kzip. Returns its digest. std::string AddSourceFile(absl::string_view path, absl::string_view content); // Adds compilation unit to the Kzip.